@whiteiOS
2017-01-10T12:22:30.000000Z
字数 6841
阅读 1864
iOS学习之路
最近好几天一直在捣鼓友盟分享及登录,由于自己作为一名iOS开发新手并且第一次接触友盟,再加上友盟分享6.0版本改动较大,遇到了大大小小好多问题,而网上的很多资料都是旧的,头疼了好几天,终于弄得差不多了,简单记录下
UMSocial文件夹拖入到项目里即可
Bulid Setting找到Other Linker Flags,添加-ObjC
libsqlite3.tbd

注意点:
1. 在第三方平台创建应用,如果只是用来测试的话,是不用填写AppStore ID的,只要创建应用就会生成appKey和appSecret并且可以拿来测试,但是Bundle ID一定要和测试应用的一致!
2. QQ:一定要填写正确应用调试者账号!如果你在腾讯开放平台登录的账号和你测试的账号不一致,就会出错!
3. Sina:一定要按照文档中说的修改安全域名以及设置授权回调页,并且还要在友盟后台绑定
URL Scheme是通过系统找到并跳转对应app的一类设置,通过向项目中的info.plist文件中加入URL types可使用第三方平台所注册的appkey信息向系统注册你的app,当跳转到第三方应用授权或分享后,可直接跳转回你的app


#import <UMSocialCore/UMSocialCore.h>- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {//打开调试日志[[UMSocialManager defaultManager] openLog:YES];//设置友盟appkey[[UMSocialManager defaultManager] setUmSocialAppkey:@"57b432afe0f55a9832001a0a"];// 获取友盟social版本号//NSLog(@"UMeng social version: %@", [UMSocialGlobal umSocialSDKVersion]);//设置微信的appKey和appSecret[[UMSocialManager defaultManager] setPlaform:UMSocialPlatformType_WechatSession appKey:@"wxdc1e388c3822c80b" appSecret:@"3baf1193c85774b3fd9d18447d76cab0" redirectURL:@"http://mobile.umeng.com/social"];//设置分享到QQ互联的appKey和appSecret[[UMSocialManager defaultManager] setPlaform:UMSocialPlatformType_QQ appKey:@"100424468" appSecret:nil redirectURL:@"http://mobile.umeng.com/social"];//设置新浪的appKey和appSecret[[UMSocialManager defaultManager] setPlaform:UMSocialPlatformType_Sina appKey:@"3921700954" appSecret:@"04b48b094faeb16683c32669824ebdad" redirectURL:@"http://sns.whalecloud.com/sina2/callback"];//支付宝的appKey[[UMSocialManager defaultManager] setPlaform: UMSocialPlatformType_AlipaySession appKey:@"2015111700822536" appSecret:nil redirectURL:@"http://mobile.umeng.com/social"];//设置易信的appKey[[UMSocialManager defaultManager] setPlaform: UMSocialPlatformType_YixinSession appKey:@"yx35664bdff4db42c2b7be1e29390c1a06" appSecret:nil redirectURL:@"http://mobile.umeng.com/social"];//设置点点虫(原来往)的appKey和appSecret[[UMSocialManager defaultManager] setPlaform: UMSocialPlatformType_LaiWangSession appKey:@"8112117817424282305" appSecret:@"9996ed5039e641658de7b83345fee6c9" redirectURL:@"http://mobile.umeng.com/social"];//设置领英的appKey和appSecret[[UMSocialManager defaultManager] setPlaform:UMSocialPlatformType_Linkedin appKey:@"81t5eiem37d2sc" appSecret:@"7dgUXPLH8kA8WHMV" redirectURL:@"https://api.linkedin.com/v1/people"];//设置Twitter的appKey和appSecret[[UMSocialManager defaultManager] setPlaform:UMSocialPlatformType_Twitter appKey:@"fB5tvRpna1CKK97xZUslbxiet" appSecret:@"YcbSvseLIwZ4hZg9YmgJPP5uWzd4zr6BpBKGZhf07zzh3oj62K" redirectURL:nil];// 如果不想显示平台下的某些类型,可用以下接口设置// [[UMSocialManager defaultManager] removePlatformProviderWithPlatformTypes:@[@(UMSocialPlatformType_WechatFavorite),@(UMSocialPlatformType_YixinTimeLine),@(UMSocialPlatformType_LaiWangTimeLine),@(UMSocialPlatformType_Qzone)]];...return YES;}
// 支持所有iOS系统- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation{BOOL result = [[UMSocialManager defaultManager] handleOpenURL:url];if (!result) {// 其他如支付等SDK的回调}return result;}
关于系统回调遇到个小坑:在进行QQ分享测试的时候,我都是发送给我的电脑,然后发现不能自动跳回应用,我就各种百度、论坛询问,反复查看URL Scheme和回调方法,就是搞不定,然后偶然发现发送给好友以及收藏的时候就能自动跳回,然后我再试了下其他的应用发送给我的电脑,竟然都是不能自动跳回的,崩溃了...
#import <UShareUI/UShareUI.h>//点击分享按钮- (IBAction)share:(id)sender {__weak typeof(self) weakSelf = self;//显示分享面板[UMSocialUIManager showShareMenuViewInView:nil sharePlatformSelectionBlock:^(UMSocialShareSelectionView *shareSelectionView, NSIndexPath *indexPath, UMSocialPlatformType platformType) {// 根据platformType调用相关平台进行分享if (platformType == UMSocialPlatformType_QQ) {[weakSelf shareWebPageToPlatformType:UMSocialPlatformType_QQ];} else if () {}...}];}
注意:
1. 官方文档里导入的头文件是UMSocialUIManager.h,我这就是导入不了,整了好久才知道,导入<UShareUI/UShareUI.h>也没问题
2. block里面的代码根据自己的需要,先判断是什么应用,然后想让应用分享视图或图片或网友就调用相关方法,具体方法在下面
3. 新浪微博分享网页没反应,要想分享网页链接的话,就选择分享文字,拼接上网页就好了
4. 为避免应用审核被拒,仅会对有效的平台进行显示,如平台应用未安装,或平台应用不支持等会进行隐藏。 由于以上原因,在模拟器上部分平台会隐藏。
- (void)shareTextToPlatformType:(UMSocialPlatformType)platformType{//创建分享消息对象UMSocialMessageObject *messageObject = [UMSocialMessageObject messageObject];//设置文本messageObject.text = @"社会化组件UShare将各大社交平台接入您的应用,快速武装App。";//调用分享接口[[UMSocialManager defaultManager] shareToPlatform:platformType messageObject:messageObject currentViewController:self completion:^(id data, NSError *error) {if (error) {NSLog(@"************Share fail with error %@*********",error);}else{NSLog(@"response data is %@",data);}}];}
UMSocialShareUIConfig.h文件中可以找的
[UMSocialShareUIConfig shareInstance].shareTitleViewConfig.isShow = NO;[UMSocialShareUIConfig shareInstance].sharePageGroupViewConfig.sharePageGroupViewMaskColor = [UIColor lightGrayColor];//分享菜单上面view的背景色[UMSocialShareUIConfig shareInstance].sharePageGroupViewConfig.sharePageGroupViewMaskViewAlpha = 0.8;//以下三句设置整个面板的背景颜色为白色[UMSocialShareUIConfig shareInstance].sharePageScrollViewConfig.shareScrollViewBackgroundColor = [UIColor whiteColor];[UMSocialShareUIConfig shareInstance].sharePageScrollViewConfig.shareScrollViewPageBGColor = [UIColor whiteColor];[UMSocialShareUIConfig shareInstance].shareContainerConfig.isShareContainerHaveGradient = false;[UMSocialShareUIConfig shareInstance].shareCancelControlConfig.shareCancelControlBackgroundColor = [UIColor whiteColor];//设置按钮里icon的宽高[UMSocialShareUIConfig shareInstance].sharePageScrollViewConfig.shareScrollViewPageMaxItemIconWidth = 50;[UMSocialShareUIConfig shareInstance].sharePageScrollViewConfig.shareScrollViewPageMaxItemIconHeight = 50;
// 在需要进行获取用户信息的UIViewController中加入如下代码#import <UMSocialCore/UMSocialCore.h>- (void)getUserInfoForPlatform:(UMSocialPlatformType)platformType{[[UMSocialManager defaultManager] getUserInfoWithPlatform:platformType currentViewController:self completion:^(id result, NSError *error) {UMSocialUserInfoResponse *userinfo =result;NSString *message = [NSString stringWithFormat:@"name: %@\n icon: %@\n gender: %@\n",userinfo.name,userinfo.iconurl,userinfo.gender];UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"UserInfo"message:messagedelegate:nilcancelButtonTitle:NSLocalizedString(@"确定", nil)otherButtonTitles:nil];[alert show];}];}
