#import "UMSocial.h" #import "UMSocialWechatHandler.h" #import "UMSocialQQHandler.h" #import "UMSocialSinaHandler.h" //友盟统计 //友盟统计分析是一款专业的移动应用统计分析工具,致力于为开发者提供实时、稳定的移动应用统计分析服务,帮助开发者更好地了解用户、优化产品以及提升转化率。友盟统计分析客户端,可以方便开发者查看应用数据,随时随地掌握应用的运营状态。 [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]); } }
时间: 2024-10-16 23:28:04