标签:
第一步:先登陆友盟账号:
如果没有友盟账号就先去注册一个友盟账号:
第二步登陆成功:
点击友盟开发者中心中的:SDK与文档
第三步:在SDK与文档中找到U-COMS微社区
点击U-COMS微社区
第四步:根据友盟的SDK步骤
第五步:下载最新的SDK然后并且把SDK包拖到工程中例如:umeng_community_ios_v2.5.0
刚刚导入SDK时候会出现跟多错误,所以接下来一步步解决
{
首先添加Framework
{
先点击工程:找到Build Phases—》Link Binary With Libraries 中添加以下的Framework
有一些Framework直接点击+号搜索不出来的需要:
1、点击Add Other按钮
2、会出现这样例如Finder的界面
3、然后点击键盘command + shift + g
4、会出现一大串英文。然后把大一大串因为改为/usr/lib
5、然后会出现很多特殊Framework找到自己需要的点击open就可以添加咯
}
}
第六步:为咯兼容iOS9的HTTP进行网络连接,在这里提醒下:网络请求都需要解决这个问题
第七步:要想使用友盟等三方登陆或分享,必须设置白名单
例如:
然后现在运行就不会报错咯:
现在如果你的应用已经在QQ上绑定第三方登录成功就可以去做友盟登陆,如果没有的话就需要去绑定第三方登陆
开始做友盟第三方登陆
先把头文件导入
#import "UMSocial.h"
#import "UMCommunity.h"
#import "UMSocialQQHandler.h"
#import "UMSocialSinaSSOHandler.h"
#import "UMSocialWechatHandler.h"
#import "UMComNavigationController.h"
#import "UMComSession.h"
#import "UMComNavigationController.h"
#import "UMSocial.h"
#import "UMSocialWechatHandler.h"
#import "UMSocialQQHandler.h"
#import "UMSocialSinaSSOHandler.h"
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[UMSocialData setAppKey:@"”];// 应用的在友盟上对应的KEY
[UMComSession openLog:YES];// 打开友盟
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
UINavigationController *navifationController = [[UINavigationController alloc] initWithRootViewController:[[ViewController alloc] init]];
self.window.rootViewController = navifationController;
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
//设置分享到QQ互联的appId和appKey
//设置微信AppId、appSecret,分享url
// 微博登陆 RedirectURL:你们软件在微博中的回调地址
[UMSocialSinaSSOHandler openNewSinaSSOWithAppKey:@“在第三方中应用邦对应key" secret:@"在第三方中应用邦对应secret" RedirectURL:@“在微博中回调地址"];
return YES;
}
下面的内容一定要写
// 登陆时候的回调会来到这里
#pragma mark Login
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
BOOL result = [UMComLoginManager handleOpenURL:url];
if (result == FALSE) {
//调用其他SDK,例如新浪微博SDK等
}
return result;
}
#pragma mark Message
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
[UMComMessageManager registerDeviceToken:deviceToken];
}
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
{
return [UMSocialSnsService handleOpenURL:url wxApiDelegate:nil];
}
- (void)applicationDidBecomeActive:(UIApplication *)application
{
[UMSocialSnsService applicationDidBecomeActive];
}
适配好这个时候:还需要在工程中对应的Info中找到URL Types这个选项
然后添加对应的URL Schemes
先QQ:
{
QQ对应有两个URL Schemes
{
例如:QQ41DC1234 —>为qq号码转化为base64的字符串前缀为QQ
tencent110491234 —>绑定第三方对应的key前缀为:tencent
}
微信:
{
例如:wxfd2dd1506b17343f —》微信号转化为base64字符串前缀为wx
}
微博:
{
例如:wb259631234 —》绑定第三方对应的key前缀为:wb
}
绑定第三方如果说的不好话可以去官网中:开发者中心—》SDK—与文档中找到—》U_Share点击集成文档:里面有账号申请及绑定
然后在登陆页面按钮对应的点击事件
- (void)qqButtonClick //qq
{
UMSocialSnsPlatform *snsPlatform = [UMSocialSnsPlatformManager getSocialPlatformWithName:UMShareToQQ];
snsPlatform.loginClickHandler(self,[UMSocialControllerService defaultControllerService],YES,^(UMSocialResponseEntity *response){
if (response.responseCode == UMSResponseCodeSuccess) {
UMSocialAccountEntity *snsAccount = [[UMSocialAccountManager socialAccountDictionary] valueForKey:UMShareToQQ];
NSLog(@"%@",snsAccount.userName);
YSHomeViewController *homeViewController= [[YSHomeViewController alloc] init];
[self.navigationController presentViewController:homeViewController animated:YES completion:nil];
}
});
}
- (void)weChatButtonClick // 微信
{
UMSocialSnsPlatform *snsPlatform = [UMSocialSnsPlatformManager getSocialPlatformWithName:UMShareToWechatSession];
snsPlatform.loginClickHandler(self,[UMSocialControllerService defaultControllerService],YES,^(UMSocialResponseEntity *response){
if (response.responseCode == UMSResponseCodeSuccess) {
UMSocialAccountEntity *snsAccount = [[UMSocialAccountManager socialAccountDictionary]valueForKey:UMShareToWechatSession];
NSLog(@"username is %@, uid is %@, token is %@ url is %@",snsAccount.userName,snsAccount.usid,snsAccount.accessToken,snsAccount.iconURL);
YSHomeViewController *homeViewController= [[YSHomeViewController alloc] init];
[self.navigationController presentViewController:homeViewController animated:YES completion:nil];
}
});}
- (void)microBlogButtonClick// 微博
{
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);
YSHomeViewController *homeViewController= [[YSHomeViewController alloc] init];
[self.navigationController presentViewController:homeViewController animated:YES completion:nil];
}});
}
// 删除授权
//[[UMSocialDataService defaultDataService] requestUnOauthWithType:UMShareToSina completion:^(UMSocialResponseEntity *response){
// NSLog(@"response is %@",response);
//}];
umeng_communitySDK第三方登陆集成
标签:
原文地址:http://www.cnblogs.com/happyEveryData/p/5514290.html