美文网首页专注iOS开发
SDK v6.2.1 友盟分享网络图片出错

SDK v6.2.1 友盟分享网络图片出错

作者: 小小的叶子随枫飘落 | 来源:发表于2017-01-16 10:30 被阅读1007次

    在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);
                }
            }];
        }];
    
    }
    
    

    相关文章

      网友评论

      • 下雨就好:我是索性直接用SDwebimage去根据链接下载图片,然后拿image对象传给友盟SDK,如果用户点击分享按钮图片还没有下载完,那就给个默认图片吧,暂时没好的办法

      本文标题:SDK v6.2.1 友盟分享网络图片出错

      本文链接:https://www.haomeiwen.com/subject/iyrebttx.html