iOS:友盟SDK第三方登录 分享及友盟统计的使用

本文转载至 http://www.it165.net/pro/html/201503/37101.html

Tag标签:第三方  
    • 01.#import "UMSocial.h"
      02.#import "UMSocialWechatHandler.h"
      03.#import "UMSocialQQHandler.h"
      04.#import "UMSocialSinaHandler.h"
      05. 
      06.//友盟统计
      07.//友盟统计分析是一款专业的移动应用统计分析工具,致力于为开发者提供实时、稳定的移动应用统计分析服务,帮助开发者更好地了解用户、优化产品以及提升转化率。友盟统计分析客户端,可以方便开发者查看应用数据,随时随地掌握应用的运营状态。
      08.[MobClickstartWithAppkey:kUMengKeyreportPolicy:SEND_ON_EXITchannelId:nil];/////开启友盟统计
      09.[MobClick setAppVersion:XcodeAppVersion];
      10.[MobClick checkUpdate];
      11. 
      12. 
      13.//友盟授权
      14.[UMSocialData setAppKey:kUMengKey];
      15.//设置微信AppId,设置分享url,默认使用友盟的网址
      16.[UMSocialWechatHandler setWXAppId:kWXAppID appSecret:kWXAppKey url:@"http://www.yshow.net"];
      17.//打开新浪微博的SSO开关
      18.[UMSocialSinaHandler openSSOWithRedirectURL:@"http://www.yshow.net"];
      19.//设置分享到<a href="http://www.it165.net/qq/qqkj/" target="_blank" class="keylink">QQ空间</a>的应用Id,和分享url 链接
      20.[UMSocialQQHandler setQQWithAppId:kQQAppID appKey:kQQAppKey url:@"http://www.yshow.net"];
      21.//设置支持没有客户端情况下使用SSO授权
      22.[UMSocialQQHandler setSupportWebView:YES];
      23. 
      24./**
      25.这里处理新浪微博SSO授权之后跳转回来,和微信分享完成之后跳转回来
      26.*/
      27.- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
      28.{
      29.return  [UMSocialSnsService handleOpenURL:url wxApiDelegate:nil];
      30.}
      31. 
      32./**
      33.这里处理新浪微博SSO授权进入新浪微博客户端后进入后台,再返回原来应用
      34.*/
      35.- (void)applicationDidBecomeActive:(UIApplication *)application
      36.{
      37.[UMSocialSnsService  applicationDidBecomeActive];
      38.}

      01.#import "UMSocial.h"
      02.//<a href="http://www.it165.net/qq/" target="_blank" class="keylink">qq</a>登录
      03.- (void)<a href="http://www.it165.net/qq/" target="_blank" class="keylink">qq</a>BtnClick:(UIButton *)btn
      04.{
      05.NSString *platformName = [UMSocialSnsPlatformManager getSnsPlatformString:UMSocialSnsTypeMobileQQ];
      06.UMSocialSnsPlatform *snsPlatform = [UMSocialSnsPlatformManager getSocialPlatformWithName:UMShareToQQ];
      07.snsPlatform.loginClickHandler(self,[UMSocialControllerService defaultControllerService],YES,^(UMSocialResponseEntity *response){
      08.NSLog(@"login response is %@",response);
      09.//获取微博用户名、uid、token等
      10.if (response.responseCode == UMSResponseCodeSuccess) {
      11.UMSocialAccountEntity *snsAccount = [[UMSocialAccountManager socialAccountDictionary] valueForKey:platformName];
      12.NSLog(@"username is %@, uid is %@, token is %@,iconUrl is %@",snsAccount.userName,snsAccount.usid,snsAccount.accessToken,snsAccount.iconURL);
      13.}
      14.});
      15.}
      16.//新浪登录
      17.- (void)sinaBtnClick:(UIButton *)btn
      18.{
      19.NSString *platformName = [UMSocialSnsPlatformManager getSnsPlatformString:UMSocialSnsTypeSina];
      20.UMSocialSnsPlatform *snsPlatform = [UMSocialSnsPlatformManager getSocialPlatformWithName:UMShareToSina];
      21.snsPlatform.loginClickHandler(self,[UMSocialControllerService defaultControllerService],YES,^(UMSocialResponseEntity *response){
      22.NSLog(@"response is %@",response);
      23.if (response.responseCode == UMSResponseCodeSuccess) {
      24.UMSocialAccountEntity *snsAccount = [[UMSocialAccountManager socialAccountDictionary] valueForKey:platformName];
      25.NSLog(@"=========%@",snsAccount.accessToken);
      26.}
      27.});
      28.}
      29. 
      30.//实现回调方法
      31.-(void)didFinishGetUMSocialDataInViewController:(UMSocialResponseEntity *)response
      32.{
      33.if (response.viewControllerType == UMSViewControllerOauth) {
      34.NSLog(@"didFinishOauthAndGetAccount response is %@",response);
      35.}
      36.}

      01.//分享
      02.typedef enum
      03.{
      04.ShareQZone,
      05.ShareQQFriend,
      06.ShareWeiXinFriend,
      07.ShareQQWB,
      08.ShareSinaWB,
      09.}ShareMode;
      10. 
      11.#import "UMSocialSnsService.h"
      12.#import "UMSocialSnsPlatformManager.h"
      13.#import "UMSocial.h"
      14. 
      15.- (void)shareFootViewSureBtnDidClick:(YSShareFootView *)view index:(ShareMode)index
      16.{
      17.NSString *shareText = @"wallpaper papehome。 http://www.wallPaper.com/social";             //分享内嵌文字
      18.UIImage *shareImage = [[SDImageCache sharedImageCache] imageFromDiskCacheForKey:self.sharedImgUrl];          //分享内嵌图片
      19. 
      20.//如果得到分享完成回调,需要设置delegate为self
      21.// @param snsNames 你要分享到的sns平台类型,该NSArray值是`UMSocialSnsPlatformManager.h`定义的平台名的字符串常量,有UMShareToSina,UMShareToTencent,UMShareToRenren,UMShareToDouban,UMShareToQzone,UMShareToEmail,UMShareToSms等
      22. 
      23.[UMSocialSnsService presentSnsIconSheetView:self appKey:kUMengKey shareText:shareText shareImage:shareImage shareToSnsNames:@[UMShareToQzone,UMShareToQQ,UMShareToWechatSession,UMShareToTencent,UMShareToSina] delegate:self];
      24.return;
      25.}
      26. 
      27.//下面得到分享完成的回调
      28.-(void)didFinishGetUMSocialDataInViewController:(UMSocialResponseEntity *)response
      29.{
      30.NSLog(@"didFinishGetUMSocialDataInViewController with response is %@",response);
      31.//根据`responseCode`得到发送结果,如果分享成功
      32.if(response.responseCode == UMSResponseCodeSuccess)
      33.{
      34.//得到分享到的微博平台名
      35.NSLog(@"share to sns name is %@",[[response.data allKeys] objectAtIndex:0]);
posted @ 2015-05-06 09:30  天牛  阅读(875)  评论(0编辑  收藏  举报