解決iOS使用友盟微博分享沒有圖片

 //創建分享消息對象
        UMSocialMessageObject *messageObject = [UMSocialMessageObject messageObject];
 
        NSString *urlKey = [[SDWebImageManager sharedManager] cacheKeyForURL:[NSURL URLWithString:self.headerModel.image]];
        UIImage *image = [[SDImageCache sharedImageCache] imageFromDiskCacheForKey:urlKey];
        //獲取不到可以顯示默認的
        if (!image) {
            image = [UIImage imageNamed:@"AppIcon"];
        }
        
        NSString *title;
        if (type == UMSocialPlatformType_Sina) {
            title = [NSString stringWithFormat:@"%@   @軟件名字", self.headerModel.title];
            UMShareImageObject *shareObject = [[UMShareImageObject alloc] init];
            shareObject.thumbImage = image;
            [shareObject setShareImage:self.headerModel.image];

            messageObject.text = [NSString stringWithFormat:@"%@  %@",title, self.headerModel.url];
            //分享消息對象設置分享內容對象
            messageObject.shareObject = shareObject;
            //調用分享接口
            [[UMSocialManager defaultManager] shareToPlatform:type messageObject:messageObject currentViewController:self completion:^(id data, NSError *error) {
                if (error) {
                    [HSToast hsShowBottomWithText:@"分享失敗"];
                }else{
                    [HSToast hsShowBottomWithText:@"分享成功"];
                }
            }];
            
        } else {
            title = self.headerModel.title;
            
            UMShareWebpageObject *shareObject = [UMShareWebpageObject shareObjectWithTitle:title descr:self.headerModel.describe thumImage:image];
            shareObject.webpageUrl = self.headerModel.url;
            messageObject.shareObject = shareObject;
            //調用分享接口
            [[UMSocialManager defaultManager] shareToPlatform:type messageObject:messageObject currentViewController:self completion:^(id data, NSError *error) {
                if (error) {
                    [HSToast hsShowBottomWithText:@"分享失敗"];
                }else{
                    [HSToast hsShowBottomWithText:@"分享成功"];
                }
            }];
        }
        

如果圖片不是https,可能會出現2014的錯誤

Error Domain=UMSocialPlatformErrorDomain Code=2014 "(null)" 

解決方案:

/*
 * 關閉強制驗證https,可允許http圖片分享,但需要在info.plist設置安全域名
 <key>NSAppTransportSecurity</key>
 <dict>
 <key>NSAllowsArbitraryLoads</key>
 <true/>
 </dict>
 */
[UMSocialGlobal shareInstance].isUsingHttpsWhenShareContent = NO;
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章