iOS 自定义分享功能(分享到微博等sahreSDK)
2015-07-01 15:50
387 查看
本次教程是参照官方的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(@"未处在登录状态!"); }
相关文章推荐
- xCode升级 插件失效
- rommon模式下给路由器灌入IOS
- iOS button被view遮住,想点击怎么破
- iOS 设置最后一行的分割线边距为零
- iOS 截取屏幕当前显示的图片(可按范围截取)
- iOS开发_统计xcode代码行数
- iOS语言中的KVO机制
- 斯坦福大学ios公开课课程源代码下载地址
- iOS代码文档化,比注释更高级!
- 查看iOS错误日志
- iOS statusBar 状态栏定制
- IOS 给类目添加属性
- iOS绘图
- iOS8学习笔记2--autolayout
- iOS开发那些事-Git在Xcode中的配置与使用常见问题总结
- ios 本地通知
- iOS 6 自动布局 入门 2
- 截取字符串
- iOS view的frame和bounds之区别(位置和大小)
- iOS 项目如何实现版本的更新?