qq,sina,微博登陆
1.申请友盟添加应用获得key
2.在qq sina 微博 添加应用信息..获得appkey.将appkey添加到友盟(分享时候用)
3.在程序中导入lib 引入若干库文件
4.关闭bitcode
5.添加URL types qq两个,微博两个,微信一个
6.添加白名单比较多 http://dev.umeng.com/social/ios/ios9#2
7.#import "UMSocial.h"
- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions {
//在友盟添加应用的key
[UMSocialData setAppKey:@"507fcab25270157b37000010"];
//qq
[UMSocialQQHandler setQQWithAppId:QQAppId appKey:QQAppKey url:QQUrl];//分享的回调url 也可以自己设置 具体看文档
[UMSocialQQHandler setSupportWebView:YES];
//微信
[UMSocialWechatHandler setWXAppId:WinxinAppId appSecret:WinxinAppSecret url:WinxinUrl];//分享的回调url 也可以自己设置 具体看文档
//打开新浪微博的SSO开关
[UMSocialSinaSSOHandler openNewSinaSSOWithAppKey:SinaAppkey RedirectURL:SinaRedirectURL]; //这个url严格按照微博的规定
}
//登陆
UMSocialSnsPlatform *snsPlatform = [UMSocialSnsPlatformManager getSocialPlatformWithName:UMShareToSina];
snsPlatform.loginClickHandler(self,[UMSocialControllerService defaultControllerService],YES,^(UMSocialResponseEntity *response){ // 获取微博用户名、uid、token等
if (response.responseCode == UMSResponseCodeSuccess) {
UMSocialAccountEntity *snsAccount = [[UMSocialAccountManager socialAccountDictionary] valueForKey:UMShareToSina];
NSLog(@"username is %@, uid is %@, token is %@ url is %@",snsAccount.userName,snsAccount.usid,snsAccount.accessToken,snsAccount.iconURL); }});
}
//分享
[UMSocialSnsService presentSnsIconSheetView:self
appKey:@"507fcab25270157b37000010"
shareText:@"友盟社会化分享让您快速实现分享等社会化功能,http://umeng.com/social"
shareImage:[UIImage imageNamed:@"icon"]
shareToSnsNames:[NSArray arrayWithObjects:UMShareToSina,UMShareToTencent,UMShareToRenren,nil]
delegate:nil]; //(如果需要代理回调则写为self)
注意:如果没有安装应用,则不添加qq 微信的分享 添加了可能导致审核失败,,而且qq空间分享的key不能用友盟默认的,有广告嫌疑
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"wechat://"]]) {
[shareName insertObject:UMShareToWechatFavorite atIndex:0];
[shareName insertObject:UMShareToWechatTimeline atIndex:0];
[shareName insertObject:UMShareToWechatSession atIndex:0];
}
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"mqq://"]]) {
[shareName insertObject:UMShareToQzone atIndex:0];
[shareName insertObject:UMShareToQQ atIndex:0];
[shareName insertObject:UMShareToWechatFavorite atIndex:0];
[shareName insertObject:UMShareToWechatTimeline atIndex:0];
[shareName insertObject:UMShareToWechatSession atIndex:0];
}
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"mqq://"]]) {
[shareName insertObject:UMShareToQzone atIndex:0];
[shareName insertObject:UMShareToQQ atIndex:0];
}