iOS:友盟SDK 第三方登入、分享及友盟統計的使用

來源:互聯網
上載者:User

標籤:ios   友盟   sdk   

#import "UMSocial.h"#import "UMSocialWechatHandler.h"#import "UMSocialQQHandler.h"#import "UMSocialSinaHandler.h"//友盟統計//友盟統計分析是一款專業的行動裝置 App統計分析工具,致力於為開發人員提供即時、穩定的行動裝置 App統計分析服務,協助開發人員更好地瞭解使用者、最佳化產品以及提升轉化率。友盟統計分析用戶端,可以方便開發人員查看應用資料,隨時隨地掌握應用的運營狀態。[MobClickstartWithAppkey:kUMengKeyreportPolicy:SEND_ON_EXITchannelId:nil];/////開啟友盟統計[MobClick setAppVersion:XcodeAppVersion];[MobClick checkUpdate];//友盟授權[UMSocialData setAppKey:kUMengKey];//設定AppId,設定分享url,預設使用友盟的網址[UMSocialWechatHandler setWXAppId:kWXAppID appSecret:kWXAppKey url:@"http://www.yshow.net"];//開啟新浪微博的SSO開關[UMSocialSinaHandler openSSOWithRedirectURL:@"http://www.yshow.net"];//設定分享到QQ空間的應用Id,和分享url 連結[UMSocialQQHandler setQQWithAppId:kQQAppID appKey:kQQAppKey url:@"http://www.yshow.net"];//設定支援沒有用戶端情況下使用SSO授權[UMSocialQQHandler setSupportWebView:YES];/** 這裡處理新浪微博SSO授權之後跳回來,和分享完成之後跳回來 */- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation{    return  [UMSocialSnsService handleOpenURL:url wxApiDelegate:nil];}/** 這裡處理新浪微博SSO授權進入新浪微部落格戶端後進入後台,再返回原來應用 */- (void)applicationDidBecomeActive:(UIApplication *)application{    [UMSocialSnsService  applicationDidBecomeActive];}

#import "UMSocial.h"//qq登入- (void)qqBtnClick:(UIButton *)btn{    NSString *platformName = [UMSocialSnsPlatformManager getSnsPlatformString:UMSocialSnsTypeMobileQQ];    UMSocialSnsPlatform *snsPlatform = [UMSocialSnsPlatformManager getSocialPlatformWithName:UMShareToQQ];    snsPlatform.loginClickHandler(self,[UMSocialControllerService defaultControllerService],YES,^(UMSocialResponseEntity *response){        NSLog(@"login response is %@",response);        //擷取微博使用者名稱、uid、token等        if (response.responseCode == UMSResponseCodeSuccess) {            UMSocialAccountEntity *snsAccount = [[UMSocialAccountManager socialAccountDictionary] valueForKey:platformName];            NSLog(@"username is %@, uid is %@, token is %@,iconUrl is %@",snsAccount.userName,snsAccount.usid,snsAccount.accessToken,snsAccount.iconURL);        }    });}//新浪登入- (void)sinaBtnClick:(UIButton *)btn{    NSString *platformName = [UMSocialSnsPlatformManager getSnsPlatformString:UMSocialSnsTypeSina];    UMSocialSnsPlatform *snsPlatform = [UMSocialSnsPlatformManager getSocialPlatformWithName:UMShareToSina];    snsPlatform.loginClickHandler(self,[UMSocialControllerService defaultControllerService],YES,^(UMSocialResponseEntity *response){       NSLog(@"response is %@",response);       if (response.responseCode == UMSResponseCodeSuccess) {           UMSocialAccountEntity *snsAccount = [[UMSocialAccountManager socialAccountDictionary] valueForKey:platformName];           NSLog(@"=========%@",snsAccount.accessToken);       }    });}//實現回調方法-(void)didFinishGetUMSocialDataInViewController:(UMSocialResponseEntity *)response{    if (response.viewControllerType == UMSViewControllerOauth) {        NSLog(@"didFinishOauthAndGetAccount response is %@",response);    }}

//分享typedef enum{    ShareQZone,    ShareQQFriend,    ShareWeiXinFriend,    ShareQQWB,    ShareSinaWB,}ShareMode;#import "UMSocialSnsService.h"#import "UMSocialSnsPlatformManager.h"#import "UMSocial.h"- (void)shareFootViewSureBtnDidClick:(YSShareFootView *)view index:(ShareMode)index{    NSString *shareText = @"wallpaper papehome。 http://www.wallPaper.com/social";             //分享內嵌文字    UIImage *shareImage = [[SDImageCache sharedImageCache] imageFromDiskCacheForKey:self.sharedImgUrl];          //分享內嵌圖片       //如果得到分享完成回調,需要設定delegate為self   // @param snsNames 你要分享到的sns平台類型,該NSArray值是`UMSocialSnsPlatformManager.h`定義的平台名的字串常量,有UMShareToSina,UMShareToTencent,UMShareToRenren,UMShareToDouban,UMShareToQzone,UMShareToEmail,UMShareToSms等    [UMSocialSnsService presentSnsIconSheetView:self appKey:kUMengKey shareText:shareText shareImage:shareImage shareToSnsNames:@[UMShareToQzone,UMShareToQQ,UMShareToWechatSession,UMShareToTencent,UMShareToSina] delegate:self];    return;}//下面得到分享完成的回調-(void)didFinishGetUMSocialDataInViewController:(UMSocialResponseEntity *)response{    NSLog(@"didFinishGetUMSocialDataInViewController with response is %@",response);    //根據`responseCode`得到發送結果,如果分享成功    if(response.responseCode == UMSResponseCodeSuccess)    {        //得到分享到的微博平台名        NSLog(@"share to sns name is %@",[[response.data allKeys] objectAtIndex:0]);    }}

iOS:友盟SDK 第三方登入、分享及友盟統計的使用

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.