#import <Social/Social.h>
#import "AppDelegate.h"
typedef void (^WeChatShareCallBackBlock)(BOOL result);
/*直接调用系统微信分享的ServiceType*/
NSString *const SystemSocialType_WeiXin=@"com.tencent.xin.sharetimeline";
/*调用系统微信分享*/
+(void)showSystemSocialWeChatShare:(NSArray *)imgArray webUrl:(NSString *)weburl completion:(WeChatShareCallBackBlock)weChatShareBlock{
if([SLComposeViewController isAvailableForServiceType:SystemSocialType_WeiXin])
{
//系统分享里有微信才行哦
if((imgArray==nil||imgArray.count>9)&&(weburl==nil||[weburl isEqualToString:@""]))
{//title 和 weburl 都为空
weChatShareBlock(NO);
}
SLComposeViewController *svc = [SLComposeViewController composeViewControllerForServiceType:SystemSocialType_WeiXin];
SLComposeViewControllerCompletionHandler myblock = ^(SLComposeViewControllerResult result){
if(result == SLComposeViewControllerResultCancelled){
NSLog(@"取消分享");
weChatShareBlock(NO);
}else{
NSLog(@"分享成功");
weChatShareBlock(YES);
}
[svc dismissViewControllerAnimated:YES completion:nil];
};
svc.completionHandler = myblock;
if(imgArray)
{
for (UIImage*image in imgArray) {
[svc addImage:image];
}
}
if(weburl)
{
[svc addURL:[NSURL URLWithString:weburl]];
}
AppDelegate *tempAppDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
[tempAppDelegate.window.rootViewController presentViewController:svc animated:YES completion:nil];
}
weChatShareBlock(NO);
}
使用系统原生分享到微信 一次分享仅支持分享图片、链接其中之一。
分享到微博可分享文本、图片、链接组合。