iOS 友盟第三方登录分享(转载)

原文地址:http://www.360doc.com/content/15/0121/14/20919452_442560039.shtml

 

// 需要引入框架

// 1. SystemConfiguration.framework

// 2. CoreGraphics.framework

// 3. libsqlite3.dylib

// 4. CoreTelephony.framework

// 5. libstdc++.dylib,

// 6. libz.dylib

 

// 下载最新的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];

 

 

 

 

 

#pragma mark 使用第三方登录需要重写下面两个方法

- (void)applicationDidBecomeActive:(UIApplication *)application

{

    // 登录需要编写

    [UMSocialSnsService applicationDidBecomeActive];

}

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString*)sourceApplication annotation:(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];

}

 

 

#pragma mark 自定义分享平台的图标、文字、点击事件

- (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"]);

        }];

    });

 

}

 

 

 

 

附录:

iOS-第三方分享-友盟分享

posted @ 2015-07-14 09:18  平平君  阅读(434)  评论(0编辑  收藏  举报