在6.2.1版本中,我在分享需要的平台的时候总是出现如下的错误
2E3CDE83-89BD-46DB-838F-55B0FC8012DB.png
后来在文档中发现友盟明确说明如需使用网络图片,确保URL为HTTPS图片链接,
AA0E3B04-2DCD-4EC0-A087-915320963590.png而我的基地址是以http开头的,总不能在把SDK换成老的版本吧。后来尝试过把网络图片转化为NSData也是行不通的,在最后通过直接从SDWebImage的缓存中找到需要分享的图片,要是找不到就分享本地图片。
NSString *urlKey = [[SDWebImageManager sharedManager] cacheKeyForURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",HOST_URL,shareImg]]];
UIImage *image = [[SDImageCache sharedImageCache] imageFromDiskCacheForKey:urlKey];
if (!image) {
image = [UIImage imageNamed:@"login_Logo.png"];
}
在最后附上分享的全部代码
.h中
/**
* 弹出分享
*/
+ (void)presentSocialSnsIconSheetViewWithObject:(id)object
shareURL:(NSString *)urlStr
shareText:(NSString *)shareText
shareTitle:(NSString *)shareTitle
shareImg:(NSString *)shareImg;
.m中
+ (void)presentSocialSnsIconSheetViewWithObject:(id)object
shareURL:(NSString *)urlStr
shareText:(NSString *)shareText
shareTitle:(NSString *)shareTitle
shareImg:(NSString *)shareImg{
//创建分享消息对象
UMSocialMessageObject *messageObject = [UMSocialMessageObject messageObject];
NSString *urlKey = [[SDWebImageManager sharedManager] cacheKeyForURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",HOST_URL,shareImg]]];
UIImage *image = [[SDImageCache sharedImageCache] imageFromDiskCacheForKey:urlKey];
if (!image) {
image = [UIImage imageNamed:@"login_Logo.png"];
}
UMShareWebpageObject *shareObject = [UMShareWebpageObject shareObjectWithTitle:shareTitle descr:shareText thumImage:image];
shareObject.webpageUrl = urlStr;
messageObject.shareObject = shareObject;
[UMSocialUIManager setPreDefinePlatforms:@[@(UMSocialPlatformType_Sina),@(UMSocialPlatformType_QQ),@(UMSocialPlatformType_Qzone),@(UMSocialPlatformType_WechatSession),@(UMSocialPlatformType_WechatTimeLine)]];
[UMSocialUIManager showShareMenuViewInWindowWithPlatformSelectionBlock:^(UMSocialPlatformType platformType, NSDictionary *userInfo) {
[[UMSocialManager defaultManager] shareToPlatform:platformType messageObject:messageObject currentViewController:object completion:^(id result, NSError *error) {
if (error) {
NSLog(@"************Share fail with error %@*********",error);
}else{
NSLog(@"response data is %@",result);
}
}];
}];
}
网友评论