分享:
1.获取友盟Appkey
1⃣️注册友盟开发者账号,登录
2⃣️添加新应用,填写基本信息,进入下载SDK并 添加代码页面,获得Appkey
2.把SDK库拖进来
3.添加代码实现:
Appdelegate:
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
{
return [UMSocialSnsService handleOpenURL:url];
}
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation
{
return [UMSocialSnsService handleOpenURL:url];
}
qq:
[UMSocialQQHandler setQQWithAppId:@"100424468" appKey:@"c7394704798a158208a74ab60104f0ba" url:@"http://www.umeng.com/social"];
//微信
[UMSocialWechatHandler setWXAppId:@"wxd930ea5d5a258f4f" appSecret:@"db426a9829e4b49a0dcac7b4162da6b6" url:@"http://www.umeng.com/social"];
其他直接在分享界面添加:
[UMSocialData defaultData].extConfig.wxMessageType = UMSocialWXMessageTypeApp;
[UMSocialSnsService presentSnsIconSheetView:self
appKey:@"550cda5456240b1cac0003d5" shareText:@"分享" shareImage:[UIImage imageNamed:@"icon.png"]
shareToSnsNames:[NSArray arrayWithObjects:UMShareToSina, UMShareToTencent,UMShareToRenren,UMShareToWechatTimeline,UMShareToWechatTimeline,UMShareToWechatSession,UMShareToQQ,UMShareToQzone,nil]
delegate:nil];
//消息链接的网址
[UMSocialData defaultData].extConfig.wechatTimelineData.url = @"http://baidu.com";
//朋友圈标题
[UMSocialData defaultData].extConfig.wechatTimelineData.title = @"朋友圈的title";
//好友标题
[UMSocialData defaultData].extConfig.wechatSessionData.title = @"好友的title";
qq,微信分享要到target,在 Info->URL Types 中添加 URL Schemes添加对应的(appID)
使用qq时 要加
- Security.framework
- libiconv.dylib
- SystemConfiguration.framework
- CoreGraphics.Framework
- libsqlite3.dylib
- CoreTelephony.framework
- libstdc++.dylib
- libz.dylib
///////登录:下面举三个几个例子,其实方法都一样的
#pragma mark - 登录
-(void)startLogin
{
//qq登录 微博登录 微信
NSArray *nameArray = @[@"QQ",@"微博",@"微信",@"人人"];
for (int i = 0; i < 4; i++ ) {
UIButton *qqBtn = [UIButton buttonWithType:UIButtonTypeSystem];
qqBtn.frame = CGRectMake(5+i*80, 100, 80, 30);
[qqBtn setBackgroundColor:[UIColor yellowColor]];
qqBtn.layer.cornerRadius = 6;
qqBtn.clipsToBounds = YES;
[qqBtn setTitle:nameArray[i] forState:UIControlStateNormal];
[qqBtn addTarget:self action:@selector(LoginBtn:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:qqBtn];
qqBtn.tag = 100+i;
}
}
#pragma mark - qqBtn
-(void)LoginBtn:(UIButton *)btn
{
NSInteger tag = btn.tag-100;
switch (tag) {
case 0:{
UMSocialSnsPlatform *snsPlatform = [UMSocialSnsPlatformManager getSocialPlatformWithName:UMShareToQQ];
snsPlatform.loginClickHandler(self,[UMSocialControllerService defaultControllerService],YES,^(UMSocialResponseEntity *response){
if (response.responseCode == UMSResponseCodeSuccess) {
UMSocialAccountEntity *snsAccount = [[UMSocialAccountManager socialAccountDictionary] valueForKey:UMShareToQQ];
NSLog(@"QQ : %@",snsAccount);
// NSLog(@"username is %@, uid is %@, token is %@ url is %@",snsAccount.userName,snsAccount.usid,snsAccount.accessToken,snsAccount.iconURL);
//-----让信息显示再界面上
UILabel *userNameLabel = [[UILabel alloc] initWithFrame:CGRectMake(10,200 , 150, 30)];
userNameLabel.text = snsAccount.userName;
[self.view addSubview:userNameLabel];
UIImageView *iconImg = [[UIImageView alloc] initWithFrame:CGRectMake(10, 250, 80, 80)];
[iconImg setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",snsAccount.iconURL]]];
[self.view addSubview:iconImg];
}});
//获取accestoken以及QQ用户信息,得到的数据在回调Block对象形参respone的data属性
[[UMSocialDataService defaultDataService] requestSnsInformation:UMShareToQQ completion:^(UMSocialResponseEntity *response){
NSLog(@"SnsInformation is %@",response.data);
}];
break;
}
case 1:{
UMSocialSnsPlatform *snsPlatform = [UMSocialSnsPlatformManager getSocialPlatformWithName:UMShareToSina];
snsPlatform.loginClickHandler(self,[UMSocialControllerService defaultControllerService],YES,^(UMSocialResponseEntity *response){
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);
//-----让信息显示再界面上
UILabel *userNameLabel = [[UILabel alloc] initWithFrame:CGRectMake(100,200 , 150, 30)];
userNameLabel.text = snsAccount.userName;
[self.view addSubview:userNameLabel];
UIImageView *iconImg = [[UIImageView alloc] initWithFrame:CGRectMake(100, 250, 80, 80)];
[iconImg setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",snsAccount.iconURL]]];
[self.view addSubview:iconImg];
}});
break;
}
case 2:{
UMSocialSnsPlatform *snsPlatform = [UMSocialSnsPlatformManager getSocialPlatformWithName:UMShareToWechatSession];
snsPlatform.loginClickHandler(self,[UMSocialControllerService defaultControllerService],YES,^(UMSocialResponseEntity *response){
if (response.responseCode == UMSResponseCodeSuccess) {
UMSocialAccountEntity *snsAccount = [[UMSocialAccountManager socialAccountDictionary] valueForKey:UMShareToWechatSession];
NSLog(@"微信 : %@",snsAccount);
// NSLog(@"username is %@, uid is %@, token is %@ url is %@",snsAccount.userName,snsAccount.usid,snsAccount.accessToken,snsAccount.iconURL);
//-----让信息显示再界面上
UILabel *userNameLabel = [[UILabel alloc] initWithFrame:CGRectMake(230,200 , 150, 30)];
userNameLabel.text = snsAccount.userName;
[self.view addSubview:userNameLabel];
UIImageView *iconImg = [[UIImageView alloc] initWithFrame:CGRectMake(200, 250, 80, 80)];
[iconImg setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",snsAccount.iconURL]]];
[self.view addSubview:iconImg];
}});
break;
}
case 3:{
UMSocialSnsPlatform *snsPlatform = [UMSocialSnsPlatformManager getSocialPlatformWithName:UMShareToRenren];
snsPlatform.loginClickHandler(self,[UMSocialControllerService defaultControllerService],YES,^(UMSocialResponseEntity *response){
if (response.responseCode == UMSResponseCodeSuccess) {
UMSocialAccountEntity *snsAccount = [[UMSocialAccountManager socialAccountDictionary] valueForKey:UMShareToRenren];
NSLog(@"人人 : %@",snsAccount);
//-----让信息显示再界面上
UILabel *userNameLabel = [[UILabel alloc] initWithFrame:CGRectMake(100,330 , 150, 30)];
userNameLabel.text = snsAccount.userName;
[self.view addSubview:userNameLabel];
UIImageView *iconImg = [[UIImageView alloc] initWithFrame:CGRectMake(100, 370, 80, 80)];
[iconImg setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",snsAccount.iconURL]]];
[self.view addSubview:iconImg];
}});
break;
}
default:
break;
}
}
浙公网安备 33010602011771号