ios开发之--友盟开发的使用
Posted 稻草人11223
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ios开发之--友盟开发的使用相关的知识,希望对你有一定的参考价值。
分享的功能,基本每个APP都会有,一般就是之前用shareSDK,后来就是友盟,还有苹果原生的,
友盟用的会多一点,也很方便,不过官方的文档有时候会看的云里雾里的,现总结一下:
1、注册应用
具体话去友盟平台上看下就行,这里不再阐述
2、集成
使用cocopods集成,具体的使用官网上都很明确了,下面只贴出代码:
target \'项目名称\' do # U-Share SDK UI模块(分享面板,建议添加) pod ‘UMengUShare/UI’ # 集成微信(精简版0.2M) pod ‘UMengUShare/Social/ReducedWeChat\' # 集成微信(完整版14.4M) pod ‘UMengUShare/Social/WeChat\' # 集成QQ/QZone/TIM(精简版0.5M) pod ‘UMengUShare/Social/ReducedQQ\' # 集成QQ/QZone/TIM(完整版7.6M) pod ‘UMengUShare/Social/QQ\' # 集成新浪微博(精简版1M) pod ‘UMengUShare/Social/ReducedSina\' # 集成新浪微博(完整版25.3M) pod ‘UMengUShare/Social/Sina\' # 集成Facebook/Messenger pod ‘UMengUShare/Social/Facebook\' # 集成Twitter pod ‘UMengUShare/Social/Twitter\' # 集成支付宝 pod ‘UMengUShare/Social/AlipayShare\' # 集成钉钉 pod ‘UMengUShare/Social/DingDing\' # 集成豆瓣 pod ‘UMengUShare/Social/Douban\' # 集成人人 pod ‘UMengUShare/Social/Renren\' # 集成腾讯微博 pod ‘UMengUShare/Social/TencentWeibo\' # 集成来往(点点虫) pod ‘UMengUShare/Social/LaiWang\' # 集成易信 pod ‘UMengUShare/Social/YiXin\' # 集成领英 pod ‘UMengUShare/Social/Linkedin\' # 集成Flickr pod ‘UMengUShare/Social/Flickr\' # 集成Kakao pod ‘UMengUShare/Social/Kakao\' # 集成Tumblr pod ‘UMengUShare/Social/Tumblr\' # 集成Pinterest pod ‘UMengUShare/Social/Pinterest\' # 集成Instagram pod ‘UMengUShare/Social/Instagram\' # 集成Line pod ‘UMengUShare/Social/Line\' # 集成WhatsApp pod ‘UMengUShare/Social/WhatsApp\' # 集成有道云笔记 pod ‘UMengUShare/Social/YouDao\' # 集成印象笔记 pod ‘UMengUShare/Social/EverNote\' # 集成Google+ pod ‘UMengUShare/Social/GooglePlus\' # 集成Pocket pod ‘UMengUShare/Social/Pocket\' # 集成DropBox pod ‘UMengUShare/Social/DropBox\' # 集成VKontakte pod ‘UMengUShare/Social/VKontakte\' # 集成邮件 pod ‘UMengUShare/Social/Email\' # 集成短信 pod ‘UMengUShare/Social/SMS\' # 加入IDFA获取 pod ‘UMengUShare/Plugin/IDFA\' end
然后执行pod install命令即可。
3、第三方平台配置
ios9以上需要增加一个可跳转APP的白名单,LSApplicationQueriesSchemes,具体内容如下:
<key>LSApplicationQueriesSchemes</key> <array> <!-- 微信 URL Scheme 白名单--> <string>wechat</string> <string>weixin</string> <!-- 新浪微博 URL Scheme 白名单--> <string>sinaweibohd</string> <string>sinaweibo</string> <string>sinaweibosso</string> <string>weibosdk</string> <string>weibosdk2.5</string> <!-- QQ、Qzone、TIM URL Scheme 白名单--> <string>mqqapi</string> <string>mqq</string> <string>mqqOpensdkSSoLogin</string> <string>mqqconnect</string> <string>mqqopensdkdataline</string> <string>mqqopensdkgrouptribeshare</string> <string>mqqopensdkfriend</string> <string>mqqopensdkapi</string> <string>mqqopensdkapiV2</string> <string>mqqopensdkapiV3</string> <string>mqqopensdkapiV4</string> <string>mqzoneopensdk</string> <string>wtloginmqq</string> <string>wtloginmqq2</string> <string>mqqwpa</string> <string>mqzone</string> <string>mqzonev2</string> <string>mqzoneshare</string> <string>wtloginqzone</string> <string>mqzonewx</string> <string>mqzoneopensdkapiV2</string> <string>mqzoneopensdkapi19</string> <string>mqzoneopensdkapi</string> <string>mqqbrowser</string> <string>mttbrowser</string> <string>tim</string> <string>timapi</string> <string>timopensdkfriend</string> <string>timwpa</string> <string>timgamebindinggroup</string> <string>timapiwallet</string> <string>timOpensdkSSoLogin</string> <string>wtlogintim</string> <string>timopensdkgrouptribeshare</string> <string>timopensdkapiV4</string> <string>timgamebindinggroup</string> <string>timopensdkdataline</string> <string>wtlogintimV1</string> <string>timapiV1</string> <!-- 支付宝 URL Scheme 白名单--> <string>alipay</string> <string>alipayshare</string> <!-- 钉钉 URL Scheme 白名单--> <string>dingtalk</string> <string>dingtalk-open</string> <!--Linkedin URL Scheme 白名单--> <string>linkedin</string> <string>linkedin-sdk2</string> <string>linkedin-sdk</string> <!-- 点点虫 URL Scheme 白名单--> <string>laiwangsso</string> <!-- 易信 URL Scheme 白名单--> <string>yixin</string> <string>yixinopenapi</string> <!-- instagram URL Scheme 白名单--> <string>instagram</string> <!-- whatsapp URL Scheme 白名单--> <string>whatsapp</string> <!-- line URL Scheme 白名单--> <string>line</string> <!-- Facebook URL Scheme 白名单--> <string>fbapi</string> <string>fb-messenger-api</string> <string>fbauth2</string> <string>fbshareextension</string> <!-- Twitter URL Scheme 白名单--> <string>twitter</string> <string>twitterauth</string> <!-- Kakao URL Scheme 白名单--> <!-- 注:以下第一个参数需替换为自己的kakao appkey--> <!-- 格式为 kakao + "kakao appkey"--> <string>kakaofa63a0b2356e923f3edd6512d531f546</string> <string>kakaokompassauth</string> <string>storykompassauth</string> <string>kakaolink</string> <string>kakaotalk-4.5.0</string> <string>kakaostory-2.9.0</string> <!-- pinterest URL Scheme 白名单--> <string>pinterestsdk.v1</string> <!-- Tumblr URL Scheme 白名单--> <string>tumblr</string> <!-- 印象笔记 --> <string>evernote</string> <string>en</string> <string>enx</string> <string>evernotecid</string> <string>evernotemsg</string> <!-- 有道云笔记--> <string>youdaonote</string> <string>ynotedictfav</string> <string>com.youdao.note.todayViewNote</string> <string>ynotesharesdk</string> <!-- Google+--> <string>gplus</string> <!-- Pocket--> <string>pocket</string> <string>readitlater</string> <string>pocket-oauth-v1</string> <string>fb131450656879143</string> <string>en-readitlater-5776</string> <string>com.ideashower.ReadItLaterPro3</string> <string>com.ideashower.ReadItLaterPro</string> <string>com.ideashower.ReadItLaterProAlpha</string> <string>com.ideashower.ReadItLaterProEnterprise</string> <!-- VKontakte--> <string>vk</string> <string>vk-share</string> <string>vkauthorize</string> </array>
4、设置URL Scheme
配置第三方平台URL Scheme未列出则不需设置
平台 | 格式 | 举例 | 备注 |
微信 | 微信appKey | wxdc1e388c3822c80b | |
QQ/Qzone | 需要添加两项URL Scheme: 1、"tencent"+腾讯QQ互联应用appID 2、“QQ”+腾讯QQ互联应用appID转换成十六进制(不足8位前面补0) |
如appID:100424468 1、tencent100424468 2、QQ05fc5b14 |
QQ05fc5b14为100424468转十六进制而来,因不足8位向前补0,然后加"QQ"前缀 |
新浪微博 | “wb”+新浪appKey | wb3921700954 | |
支付宝 | “ap”+appID | ap2015111700822536 | URL Type中的identifier填"alipayShare" |
钉钉 | 钉钉appkey | dingoalmlnohc0wggfedpk | identifier的参数都使用dingtalk |
易信 | 易信appkey | yx35664bdff4db42c2b7be1e29390c1a06 | |
点点虫 | 点点虫appID | 8112117817424282305 | URL Type中的identifier填"Laiwang" |
领英 | “li”+appID | li4768945 | |
“fb”+FacebookID | fb506027402887373 | ||
“twitterkit-”+TwitterAppkey | twitterkit-fB5tvRpna1CKK97xZUslbxiet | ||
VKontakte | “vk”+ VKontakteID | vk5786123 |
5、项目设置
初始化U-Share:
[UMConfigure initWithAppkey:@"app-key" channel:@"App Store"];
初始化第三方平台:
- (void)configUSharePlatforms { /* 设置微信的appKey和appSecret */ [[UMSocialManager defaultManager] setPlaform:UMSocialPlatformType_WechatSession appKey:@"wxdc1e388c3822c80b" appSecret:@"3baf1193c85774b3fd9d18447d76cab0" redirectURL:@"http://mobile.umeng.com/social"]; /*设置小程序回调app的回调*/ [[UMSocialManager defaultManager] setLauchFromPlatform:(UMSocialPlatformType_WechatSession) completion:^(id userInfoResponse, NSError *error) { NSLog(@"setLauchFromPlatform:userInfoResponse:%@",userInfoResponse); }]; /* * 移除相应平台的分享,如微信收藏 */ //[[UMSocialManager defaultManager] removePlatformProviderWithPlatformTypes:@[@(UMSocialPlatformType_WechatFavorite)]]; /* 设置分享到QQ互联的appID * U-Share SDK为了兼容大部分平台命名,统一用appKey和appSecret进行参数设置,而QQ平台仅需将appID作为U-Share的appKey参数传进即可。 */ [[UMSocialManager defaultManager] setPlaform:UMSocialPlatformType_QQ appKey:@"1105821097"/*设置QQ平台的appID*/ appSecret:nil redirectURL:@"http://mobile.umeng.com/social"]; /* 设置新浪的appKey和appSecret */ [[UMSocialManager defaultManager] setPlaform:UMSocialPlatformType_Sina appKey:@"3921700954" appSecret:@"04b48b094faeb16683c32669824ebdad" redirectURL:@"https://sns.whalecloud.com/sina2/callback"]; /* 钉钉的appKey */ [[UMSocialManager defaultManager] setPlaform: UMSocialPlatformType_DingDing appKey:@"dingoalmlnohc0wggfedpk" appSecret:nil redirectURL:nil]; /* 支付宝的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]; /* 设置Facebook的appKey和UrlString */ [[UMSocialManager defaultManager] setPlaform:UMSocialPlatformType_Facebook appKey:@"506027402887373" appSecret:nil redirectURL:@"http://www.umeng.com/social"]; /* 设置Pinterest的appKey */ [[UMSocialManager defaultManager] setPlaform:UMSocialPlatformType_Pinterest appKey:@"4864546872699668063" appSecret:nil redirectURL:nil]; /* dropbox的appKey */ [[UMSocialManager defaultManager] setPlaform: UMSocialPlatformType_DropBox appKey:@"k4pn9gdwygpy4av" appSecret:@"td28zkbyb9p49xu" redirectURL:@"https://mobile.umeng.com/social"]; /* vk的appkey */ [[UMSocialManager defaultManager] setPlaform:UMSocialPlatformType_VKontakte appKey:@"5786123" appSecret:nil redirectURL:nil]; }
设置系统回调方法:
支持目前所有iOS系统
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url { BOOL result = [[UMSocialManager defaultManager] handleOpenURL:url]; if (!result) { // 其他如支付等SDK的回调 } return result; }
6、分享的消息类型
- 网页类型(包含 标题+描述+icon 的卡片,点击会进入配置的url)
- 图片
- 文本
- 表情(GIF图片,即Emotion类型,只有微信支持)
- 图文(包含一张图片和一段文本)
- 视频(只支持视频URL、缩略图及描述)
- 音乐(只支持音乐URL、缩略图及描述)
a、分享文本
- (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); } }]; }
b、分享图片
- (void)shareImageToPlatformType:(UMSocialPlatformType)platformType { //创建分享消息对象 UMSocialMessageObject *messageObject = [UMSocialMessageObject messageObject]; //创建图片内容对象 UMShareImageObject *shareObject = [[UMShareImageObject alloc] init]; //如果有缩略图,则设置缩略图 shareObject.thumbImage = [UIImage imageNamed:@"icon"]; [shareObject setShareImage:@"https://mobile.umeng.com/images/pic/home/social/img-1.png"]; //分享消息对象设置分享内容对象 messageObject.shareObject = shareObject; //调用分享接口 [[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); } }]; }
c、分享图文(新浪支持,微信/QQ仅支持图或文本分享)
- (void)shareImageAndTextToPlatformType:(UMSocialPlatformType)platformType { //创建分享消息对象 UMSocialMessageObject *messageObject = [UMSocialMessageObject messageObject]; //设置文本 messageObject.text = @"社会化组件UShare将各大社交平台接入您的应用,快速武装App。"; //创建图片内容对象 UMShareImageObject *shareObject = [[UMShareImageObject alloc] init]; //如果有缩略图,则设置缩略图 shareObject.thumbImage = [UIImage imageNamed:@"icon"]; [shareObject setShareImage:@"https://www.umeng.com/img/index/demo/1104.4b2f7dfe614bea70eea4c6071c72d7f5.jpg"]; //分享消息对象设置分享内容对象 messageObject.shareObject = shareObject; //调用分享接口 [[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); } }]; }
d、分享网页
- (void)shareWebPageToPlatformType:(UMSocialPlatformType)platformType { //创建分享消息对象 UMSocialMessageObject *messageObject = [UMSocialMessageObject messageObject]; //创建网页内容对象 UMShareWebpageObject *shareObject = [UMShareWebpageObject shareObjectWithTitle:@"分享标题" descr:@"分享内容描述" thumImage:[UIImage imageNamed:@"icon"]]; //设置网页地址 shareObject.webpageUrl =@"http://mobile.umeng.com/social"; //分享消息对象设置分享内容对象 messageObject.shareObject = shareObject; //调用分享接口 [[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); } }]; }
e、分享音乐
- (void)shareMusicToPlatformType:(UMSocialPlatformType)platformType { //创建分享消息对象 UMSocialMessageObject *messageObject = [UMSocialMessageObject messageObject]; //创建音乐内容对象 UMShareMusicObject *shareObject = [UMShareMusicObject shareObjectWithTitle:@"分享标题" descr:@"分享内容描述" thumImage:[UIImage imageNamed:@"icon"]]; //设置音乐网页播放地址 shareObject.musicUrl = @"http://c.y.qq.com/v8/playsong.html?songid=108782194&source=yqq#wechat_redirect"; // shareObject.musicDataUrl = @"这里设置音乐数据流地址(如果有的话,而且也要看所分享的平台支不支持)"; //分享消息对象设置分享内容对象 messageObject.shareObject = shareObject; //调用分享接口 [[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); } }]; }
f、分享视频
- (void)shareVedioToPlatformType:(UMSocialPlatformType)platformType { //创建分享消息对象 UMSocialMessageObject *messageObject = [UMSocialMessageObject messageObject]; //创建视频内容对象 UMShareVideoObject *shareObject = [UMShareVideoObject shareObjectWithTitle:@"分享标题" descr:@"分享内容描述" thumImage:[UIImage imageNamed:@"icon"]]; //设置视频网页播放地址 shareObject.videoUrl = @"http://video.sina.com.cn/p/sports/cba/v/2013-10-22/144463050817.html"; // shareObject.videoStreamUrl = @"这里设置视频数据流地址(如果有的话,而且也要看所分享的平台支不支持)"; //分享消息对象设置分享内容对象 messageObject.shareObject = shareObject; //调用分享接口 [[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); } }]; }
调用分享面板
#import <UShareUI/UShareUI.h> NSArray * platformTypes = @[@1,@2]; [UMSocialUIManager setPreDefinePlatforms:platformTypes]; [UMSocialUIManager showShareMenuViewInWindowWithPlatformSelectionBlock:^(UMSocialPlatformType platformType, NSDictionary *userInfo) { // 根据获取的platformType确定所选平台进行下一步操作 [self shareTextToPlatformType:platformType]; }];
其他,是否安装微信:
#import "WXApi.h" if ([WXApi isWXAppInstalled]) { //已经安装微信 }
仅做记录!
参考自:https://www.cnblogs.com/zhujiabin/p/9936442.html
官方文档:https://developer.umeng.com/docs/128606/detail/129443#h3--url-scheme
以上是关于ios开发之--友盟开发的使用的主要内容,如果未能解决你的问题,请参考以下文章
iOS开发CGRectGetMidX. CGRectGetMidY.CGRectGetMinY. CGRectGetMaxY. CGRectGetMinX. CGRectGetMaxX的使用(代码片段
iOS开发CGRectGetMidX. CGRectGetMidY.CGRectGetMinY. CGRectGetMaxY. CGRectGetMinX. CGRectGetMaxX的使用(代码片段