msg解决shareSDK分享失败问题

1.分享的url为空或者含特殊字符(未编码)导致分享失败

解决:

判空

url编码:

self.rootView.shareUrl = [self.rootView.shareUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

2.分享的图片过大,导致分享失败

解决:压缩图片

<span style="font-size:14px;">//压缩图片,img:图像 maxByte:压缩后的最大字节
-(UIImage*)compressImage:(UIImage*)img maxByte:(NSUInteger)maxByte
{
	CGFloat scale=1;
	NSData *imgData = UIImageJPEGRepresentation(img, scale);
	if (imgData.length > maxByte) {
		scale = maxByte*1.0/imgData.length;
		imgData = UIImageJPEGRepresentation(img, scale);
		img = [UIImage imageWithData:imgData];
	}
//	NSLog(@"-------%lu",(unsigned long)imgData.length);
	return  img;
}</span><span style="font-size: 18px;">
</span>

3、ios9之后shareSDK需要适配,否则无法分享

(1)网络适配

iOS9引入了新特性App Transport Security (ATS)。详情:App Transport Security (ATS)

新特性要求App内访问的网络必须使用HTTPS协议。
但是现在公司的项目使用的是HTTP协议,使用私有加密方式保证数据安全。现在也不能马上改成HTTPS协 议传 输。

解决办法:

  1. 在Info.plist中添加NSAppTransportSecurity类型Dictionary
  2. NSAppTransportSecurity下添加NSAllowsArbitraryLoads类型Boolean,值设为YES

(2)分享白名单

配置详情参考官方:http://wiki.mob.com/ios9-%E5%AF%B9sharesdk%E7%9A%84%E5%BD%B1%E5%93%8D%EF%BC%88%E9%80%82%E9%85%8Dios-9%E5%BF%85%E8%AF%BB%EF%BC%89/

猜你喜欢

转载自blog.csdn.net/ZhangWangYang/article/details/50350837