1.分享功能弹出控制面板
[UMSocialSnsService presentSnsIconSheetView:self
appKey:@"507fcab25270157b37xxxxxx"
shareText:@"你要分享的文字"
shareImage:[UIImage imageNamed:@"icon.png"]
shareToSnsNames:[NSArray arrayWithObjects:UMShareToSina,UMShareToWechatSession,UMShareToQQ,nil]
delegate:self];
形参名 | 含义 |
---|---|
controller | 分享列表页面所在的UIViewController对象 |
appKey | 友盟appKey,如果你在其他地方用UMSocialData 设置了appKey,这里也可以传nil |
shareText | 分享编辑页面的内嵌文字 |
shareImage | 分享编辑页面的内嵌图片,用户可以在编辑页面中删除。如果你不需要分享图片,可以传入nil |
shareToSnsNames | 定义列表出现的微博平台字符串构成的数组,字符变量名为UMShareToSina、UMShareToTencent、UMShareToWechatSession、UMShareToWechatTimeline、UMShareToQzone、UMShareToQQ、UMShareToRenren、UMShareToDouban、UMShareToEmail、UMShareToSms、UMShareToFacebook、UMShareToTwitter,分别代表新浪微博、腾讯微博、微信好友、微信朋友圈、QQ空间、手机QQ、人人网、豆瓣、电子邮箱、短信、Facebook、Twitter |
delegate | 实现分享状态回调方法的对象,回调方法的实现可以参见分享详细说明的回调方法部分。如果你不需要回调的话,可以设为nil |
2.点击微信分享,弹框说微信未安装(实际已经安装了)
1).HTTP传输安全
A、在info.plist中加入安全域名白名单(右键info.plist用source code打开)
<key>NSAppTransportSecurity</key>
<dict>
<key>NSExceptionDomains</key>
<dict>
<key>log.umsns.com</key>
<dict> <key>NSIncludesSubdomains</key>
<true/>
<key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
<true/>
<key>NSTemporaryExceptionMinimumTLSVersion</key>
<string>TLSv1.1</string>
</dict>
<key>sns.whalecloud.com</key>
<dict>
<key>NSIncludesSubdomains</key>
<true/>
<key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
<true/>
<key>NSTemporaryExceptionMinimumTLSVersion</key>
<string>TLSv1.1</string>
</dict>
<!-- 集成QQ授权对应的HTTP白名单-->
<key>qq.com</key>
<dict>
<key>NSIncludesSubdomains</key>
<true/>
<key>NSThirdPartyExceptionAllowsInsecureHTTPLoads</key>
<true/>
<key>NSThirdPartyExceptionRequiresForwardSecrecy</key>
<false/>
</dict>
B、在info.plist的NSAppTransportSecurity下新增NSAllowsArbitraryLoads并设置为YES,指定所有HTTP连接都可正常请求
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
2).应用跳转(SSO等)
如果你的应用使用了如SSO授权登录或跳转分享功能,在iOS9下就需要增加一个可跳转的白名单,指定对应跳转App的URL Scheme,
否则将在第三方平台判断是否跳转时用到的canOpenURL时返回NO,进而只进行webview授权或授权/分享失败。
同样在info.plist增加
<key>LSApplicationQueriesSchemes</key>
<array>
<!-- 微信 URL Scheme 白名单-->
<string>wechat</string>
<string>weixin</string>
</array>
参考:http://dev.umeng.com/social/ios/ios9
3.分享的数据信息没有带过去问题
[[ShareEngine sharedInstance] sendWeChatMessage:nil
url:momentUrl
shareType:SHARE_ENGINE_FRIEND
titleString:titleString
description:nil
thubnilImage:scaleImage];
- (void)sendWeChatMessage:(NSString*)message
url:(NSString*)url
shareType:(int)shareType
titleString:(NSString *)strTitle
description:(NSString *)description
thubnilImage:(UIImage *)thubnilImage
{
switch (shareType)
{
case SHARE_ENGINE_FRIEND: // 好友
{
SendMessageToWXReq *req = [[SendMessageToWXReq alloc] init];
req.bText = NO;
// 发送媒体消息给微信
WXMediaMessage *mediaMessage = [WXMediaMessage message];
mediaMessage.title = strTitle;
mediaMessage.description = SHARE_WECHAT_CONTENT;
if (thubnilImage) {
[mediaMessage setThumbImage: thubnilImage];
}
else
{
[mediaMessage setThumbImage: [UIImage imageNamed:@"icon_logo"]];
}
WXWebpageObject *ext = [WXWebpageObject object];
ext.webpageUrl = url;
mediaMessage.mediaObject = ext;
req.message = mediaMessage;
req.scene = SHARE_ENGINE_FRIEND;
[WXApi sendReq:req];
}
break;
case SHARE_ENGINE_FRIEND_CIRCLE: // 好友圈
{
SendMessageToWXReq *req = [[SendMessageToWXReq alloc] init];
req.bText = NO;
// 发送媒体消息给微信
WXMediaMessage *mediaMessage = [WXMediaMessage message];
mediaMessage.title = strTitle;
mediaMessage.description = description;
[mediaMessage setThumbImage: thubnilImage];
WXWebpageObject *ext = [WXWebpageObject object];
ext.webpageUrl = url;
mediaMessage.mediaObject = ext;
req.message = mediaMessage;
req.scene = SHARE_ENGINE_FRIEND_CIRCLE;
[WXApi sendReq:req];
}
break;
default:
break;
}
}
4.修改分享面板上的文字和图片
UMSocialSnsPlatform *wenxinCirclePlatform = [UMSocialSnsPlatformManager getSocialPlatformWithName:UMShareToWechatTimeline];
wenxinCirclePlatform.bigImageName = @"icon_share_friend_circle";
wenxinCirclePlatform.displayName = @"朋友圈";
wenxinCirclePlatform.snsClickHandler = ^(UIViewController *presentingController, UMSocialControllerService * socialControllerService, BOOL isPresentInController){
NSLog(@"点击微信朋友圈的响应");
[[ShareEngine sharedInstance] sendWeChatMessage:nil
url:momentUrl
shareType:SHARE_ENGINE_FRIEND_CIRCLE
titleString:titleString
description:nil
thubnilImage:scaleImage];
};