本次教程是参照官方的shareSDK进行操作(按照教程进行前期的准备操作,该导入的导入,该添加的添加)
做完前期准备工作然后进行下面的操作
首先要对需求的分享方式进行声明
/** * 分享方式的声明引用 */ [ShareSDK registerApp:@"3df7a36158b2"]; [ShareSDK connectSinaWeiboWithAppKey:@"568898243" appSecret:@"38a4f8204cc784f81f9f0daaf31e02e3" redirectUri:@"http://www.sharesdk.cn"];
选择分享的途径以及制定分享的内容
//选择分享的途径
switch (sender.tag) { case 11: type = ShareTypeYiXinSession; break; case 12: type = ShareTypeYiXinTimeline; break; case 13: type = ShareTypeWeixiSession; break; case 14: type = ShareTypeWeixiTimeline ; break; case 15: type = ShareTypeSinaWeibo; break; case 16: type = ShareTypeQQ ; break; case 17: type = ShareTypeQQSpace; break; case 18: type = ShareTypeRenren; break; case 19: type = ShareTypeSMS; break; case 20: type = ShareType163Weibo; break; case 21: type = ShareTypeTencentWeibo; break; case 22: type = ShareTypeEvernote; break; case 23: type = ShareTypeInstapaper; break; case 24: type = ShareTypeMail; break; case 25: type = ShareTypeYouDaoNote; break; case 26: type = ShareTypePocket; break; default: break; } //分享内容等参数的制定 id<ISSContent> publishContent = [ShareSDK content:userWriteTextView.text defaultContent:nil image:[ShareSDK pngImageWithImage:shareImage] title:@"This is title" url:@"http://mob.com" description:@"This is description" mediaType:SSPublishContentMediaTypeNews]; //2.分享 [ShareSDK shareContent:publishContent type:type authOptions:nil shareOptions:nil statusBarTips:YES result:^(ShareType type, SSResponseState state, id<ISSPlatformShareInfo> statusInfo, id<ICMErrorInfo> error, BOOL end) { if (state == SSPublishContentStateSuccess){ NSLog(@"分享成功"); UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"" message:@"分享成功" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil]; [alert show]; } else if (state == SSPublishContentStateFail){ NSLog(@"分享失败,错误码:%ld,错误描述%@",(long)[error errorCode],[error errorDescription]); UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"" message:@"分享失败,请看日记错误描述" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil]; [alert show]; } }]; }
下面的这个方法是判断用户是否登录的
</pre><pre name="code" class="objc"> id<ISSPlatformCredential> credential = [ShareSDK getCredentialWithType:ShareTypeSinaWeibo]; if(credential!=nil&&[credential available]){ NSLog(@"处在登录状态!"); }else { NSLog(@"未处在登录状态!"); }
时间: 2024-10-19 09:38:51