iOS友盟第三方登录分享
2016-05-01 18:23
489 查看
// 需要引入框架 // 1. SystemConfiguration.framework // 2. CoreGraphics.framework // 3. libsqlite3.dylib // 4. CoreTelephony.framework // 5. libstdc++.dylib, // 6. libz.dylib // 7. Security.framework // 8. libiconv.framework // 下载最新的SDK,http://dev.umeng.com/social/ios/sdk-download // 将UMSocial_Sdk-x.x.x的文件夹拖入工程目录下 //libUMSocial_Sdk-x.x.x.a libUMSocial_Sdk_comment_3.0.a 库文件 // Header 头文字 // SocialSDKXib xib文件 // en.Iproj,zh-Hans.Iproj 英文和中文语言文件 //frameworks 使用的第三方SDK,里面的Wechat,TencentOperAPI,TencentWeiboSSO,分别代表微信、手机QQ和腾讯微博SDK
// 设置友盟分享 [UMSocialData setAppKey:@"52b13dc556240b55870e7148"]; // 设置手机QQ的使用 [UMSocialConfig setQQAppId:@"100424468" url:nil importClasses:@[[QQApiInterface class], [TencentOAuthclass]]]; // 设置微信功能 [UMSocialConfig setWXAppId:@"wx34bd7147c4d8ad5a" url:nil];
#pragmamark 使用第三方登录需要重写下面两个方法 - (void)applicationDidBecomeActive:(UIApplication *)application { // 登录需要编写 [UMSocialSnsService applicationDidBecomeActive]; } - (BOOL)application:(UIApplication *)applicationopenURL:(NSURL *)urlsourceApplication:(NSString*)sourceApplicationannotation:(id)annotation { return [UMSocialSnsService handleOpenURL:url wxApiDelegate:nil]; }
#pragma mark 直接分享 - (IBAction)share:(id)sender { // 设置分享内容与分享平台 // 弹出UIActivityViewController样式的列表 [UMSocialSnsService presentSnsIconSheetView:self appKey:Nil shareText:@"要分享的内容" shareImage:nilshareToSnsNames:@[UMShareToQzone, UMShareToSina, UMShareToTencent, UMShareToRenren,UMShareToSms,UMShareToEmail, UMShareToFacebook, UMShareToTwitter, UMShareToWechatSession, UMShareToWechatTimeline,UMShareToQQ] delegate:nil]; }
#pragmamark 自定义分享平台的图标、文字、点击事件 - (IBAction)diyPlatformInfo:(id)sender { // 获取到新浪微博分享平台 UMSocialSnsPlatform *sinaPlatform= [UMSocialSnsPlatformManagergetSocialPlatformWithName:UMShareToSina]; // 设置平台图片 sinaPlatform.bigImageName = @"sina_icon@2x.png"; // 设置平台名称 sinaPlatform.displayName = @"新浪的微博"; // 设置点击平台图标的事件 sinaPlatform.snsClickHandler =^(UIViewController *presentingController, UMSocialControllerService*socialControllerService, BOOL isPresentInController){ NSLog(@"点击了新浪微博分享"); }; // 弹出UITableView样式的分享列表 [UMSocialSnsService presentSnsController:self appKey:nil shareText:@"要分享的内容" shareImage:nilshareToSnsNames:@[UMShareToSina] delegate:nil]; }
#pragma mark 设置分享的类型 - (IBAction)shareType:(id)sender { // 设置分享音乐类型 [[UMSocialData defaultData].urlResource setResourceType:UMSocialUrlResourceTypeMusic]; // 设置图片类型并附带网址 [[UMSocialData defaultData].urlResource setResourceType:UMSocialUrlResourceTypeImageurl:@"http://baike.steelhome.cn/uploads/200912/1262062983nmcUZA6K.jpg"]; // 设置视频类型,并附带网址 [[UMSocialData defaultData].urlResource setResourceType:UMSocialUrlResourceTypeVideourl:@"http://www.baidu.com/video/benshankuaileying/4324343244320.mp4"]; // 显示各个平台类型 [UMSocialSnsService presentSnsIconSheetView:self appKey:Nil shareText:@"要分享的内容" shareImage:nilshareToSnsNames:@[UMShareToSina] delegate:nil]; }
#pragma mark 分享到QQ - (IBAction)shareToQQ:(id)sender { [UMSocialSnsService presentSnsIconSheetView:self appKey:nil shareText:@"发送分享内容" shareImage:nilshareToSnsNames:@[UMShareToQQ] delegate:nil]; }
#pragma mark 微信分享 - (IBAction)shareWeiXin:(id)sender { // 设置微信分享应用类型,用户点击消息将跳转到应用,或者到下载页面 //UMSocialWXMessageTypeImage为图片类型 [UMSocialData defaultData].extConfig.wxMessageType = UMSocialWXMessageTypeApp; // 分享图盘到微信朋友圈显示字数比较少,只显示分享标题 [UMSocialData defaultData].extConfig.title = @"朋友圈分享内容"; // 显示分享平台 [UMSocialSnsService presentSnsController:self appKey:nil shareText:@"分享的内容" shareImage:nilshareToSnsNames:@[UMShareToWechatSession, UMShareToWechatTimeline] delegate:nil]; }
#pragma mark 第三方登录 - (IBAction)otherLogin:(id)sender { // 使用Sina微博账号登录 UMSocialSnsPlatform *snsPlatform= [UMSocialSnsPlatformManagergetSocialPlatformWithName:UMShareToSina]; snsPlatform.loginClickHandler(self,[UMSocialControllerService defaultControllerService], YES,^(UMSocialResponseEntity *response) { NSLog(@"response is %@", response); // 如果是授权到新浪微博,SSO之后如果想获取用户的昵称、头像等需要再获取一次账户信息 [[UMSocialDataService defaultDataService]requestSocialAccountWithCompletion:^(UMSocialResponseEntity *response){ // 打印用户昵称 NSLog(@"SinaWeibo's user name is%@",[[[response.data objectForKey:@"accounts"]objectForKey:UMShareToSina] objectForKey:@"username"]); }]; }); }
相关文章推荐
- TableView点击状态栏滑动到顶部无效时如何处理
- iOS - 计步器
- iOS - 摇一摇
- iOS - 加速计程序的开发
- iOS视图控制器编程指南 --- 定义你的子类
- iOS - 距离传感器
- iOS自定义progressView的实现
- ios拼图游戏(三)之使用TableView布局
- iOS SDL2静态库的编译
- iOS开发踩过的坑
- iOS开发资源大全
- IOS安全学记资料汇总
- iOS的学习资料
- ios拼图游戏(二)之长按手势和拖动手势的区别
- iOS下使用FFMPEG
- IOS 杂笔-18 (let 与 var)
- iOS开发之--内购、GameCenter、iCloud、Passbook功能开发汇总
- 闲话iOS的MVC设计模式
- iOS边练边学--AFNetWorking框架GET、Post、Download、Upload,数据解析模式以及监控联网状态
- iOS9 新增特性(汇)