Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit e2d68a7

Browse files
分享带图片的资源时,添加图片
1 parent 5439931 commit e2d68a7

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

‎Coding_iOS/.DS_Store

0 Bytes
Binary file not shown.

‎Coding_iOS/Images/logo_about@2x.png

100755100644
2.82 KB
Loading[フレーム]

‎Coding_iOS/Views/CodingShareView.m

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,13 @@ - (void)p_doShareToSnsName:(NSString *)snsName{
286286
}
287287
NSString *shareContent = [NSString stringWithFormat:@"%@%@%@", shareTitle, shareText, shareTail];
288288
[self showStatusBarQueryStr:@"正在分享到新浪微博"];
289-
[[UMSocialDataService defaultDataService] postSNSWithTypes:@[UMShareToSina] content:shareContent image:nil location:nil urlResource:nil presentedController:[BaseViewController presentingVC] completion:^(UMSocialResponseEntity *response) {
289+
290+
UMSocialUrlResource *urlResource = nil;
291+
NSString *imageUrl = [self p_imageUrl];
292+
if (imageUrl.length > 0) {
293+
urlResource = [[UMSocialUrlResource alloc] initWithSnsResourceType:UMSocialUrlResourceTypeImage url:imageUrl];
294+
}
295+
[[UMSocialDataService defaultDataService] postSNSWithTypes:@[UMShareToSina] content:shareContent image:nil location:nil urlResource:urlResource presentedController:[BaseViewController presentingVC] completion:^(UMSocialResponseEntity *response) {
290296
if (response.responseCode == UMSResponseCodeSuccess) {
291297
[self showStatusBarSuccessStr:@"分享成功"];
292298
}else{
@@ -366,6 +372,19 @@ - (NSString *)p_shareText{
366372
}
367373
return text;
368374
}
375+
- (NSString *)p_imageUrl{
376+
__block NSString *imageUrl = nil;
377+
if ([_objToShare respondsToSelector:NSSelectorFromString(@"htmlMedia")]) {
378+
HtmlMedia *htmlMedia = [_objToShare valueForKey:@"htmlMedia"];
379+
[htmlMedia.imageItems enumerateObjectsUsingBlock:^(HtmlMediaItem *obj, NSUInteger idx, BOOL *stop) {
380+
if (obj.type == HtmlMediaItemType_Image) {
381+
imageUrl = obj.src;
382+
*stop = YES;
383+
}
384+
}];
385+
}
386+
return imageUrl;
387+
}
369388
#pragma mark TranspondMessage
370389

371390
- (void)willTranspondMessage:(PrivateMessage *)message{
@@ -398,7 +417,14 @@ -(void)didSelectSocialPlatform:(NSString *)platformName withSocialData:(UMSocial
398417
//设置分享内容,和回调对象
399418
{
400419
socialData.shareText = [self p_shareText];
401-
socialData.shareImage = [UIImage imageNamed:@"logo_about"];
420+
NSString *imageUrl = [self p_imageUrl];
421+
if (imageUrl.length > 0) {
422+
socialData.urlResource = [[UMSocialUrlResource alloc] initWithSnsResourceType:UMSocialUrlResourceTypeImage url:imageUrl];
423+
socialData.shareImage = nil;
424+
}else{
425+
socialData.urlResource = nil;
426+
socialData.shareImage = [UIImage imageNamed:@"logo_about"];
427+
}
402428
}
403429
if ([platformName isEqualToString:@"wxsession"]) {
404430
UMSocialWechatSessionData *wechatSessionData = [UMSocialWechatSessionData new];

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /