Objective-c 不调用微信api 直接调用系统微信分享

最近有个需求直接调用系统的微信分享,网上搜了好多都是系统有的Facebook和新浪微博的,没有看到微信,如果取到了微信的ServiceType不是就可以像分享到新浪微博一样调用系统分享了吗

/*直接调用系统微信分享的ServiceType*/
NSString *const SystemSocialType_WeiXin=@"com.tencent.xin.sharetimeline";

/*调用系统微信分享*/
+(BOOL)showSystemSocialWeiXinShare:(NSString *)title webUrl:(NSString *)weburl viewController:(UIViewController*)viewController
{
    if([SLComposeViewController isAvailableForServiceType:SystemSocialType_WeiXin])
    {//系统分享里有微信才行哦
        if((title==nil||[title isEqualToString:@""])&&(weburl==nil||[weburl isEqualToString:@""]))
        {//title 和 weburl 都为空
            return NO;
        }
        SLComposeViewController *svc = [SLComposeViewController composeViewControllerForServiceType:SystemSocialType_WeiXin];
        
        
        SLComposeViewControllerCompletionHandler myblock = ^(SLComposeViewControllerResult result){
            if(result == SLComposeViewControllerResultCancelled){
                NSLog(@"cancel");
            }else{
                NSLog(@"done");
            }
            [svc dismissViewControllerAnimated:YES completion:nil];
        };
        svc.completionHandler = myblock;
        if(title)
        {
            [svc setInitialText:title];
        }
        if(weburl)
        {
            [svc addURL:[NSURL URLWithString:weburl]];
        }
        
        [viewController presentViewController:svc animated:YES completion:nil];
        return YES;
    }
    return NO;
}

如何找到微信系统分享的ServiceType了,如下

/*
打开系统分享面板 
NSLog(@"activityType --------%@",activityType); 即可看到需要的activityType
*/
+(BOOL)showSystemShare:(NSString *)title imageUrl:(NSString *)imageUrl webUrl:(NSString *)webUrl viewController:(UIViewController*)viewController ipadPopView:(UIView *)ipadPopView
{
    NSMutableArray *activityItems=[[NSMutableArray alloc] init];
    if(imageUrl&&![imageUrl isEqualToString:@""])
    {
        NSURL *thumbUrl=[NSURL URLWithString:[[NSString stringWithFormat:@"%@",imageUrl] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding] ];
        UIImage *image=[UIImage imageWithData:[NSData dataWithContentsOfURL:thumbUrl]];
        [activityItems addObject:image];
    }
    if(webUrl)
    {
        [activityItems addObject:[NSURL URLWithString:webUrl]];
    }
    
    if(title)
    {
        [activityItems addObject:title];
    }
    
    if(activityItems.count<=0)
    {
        return NO;
    }
    UIActivityViewController *activity=[[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:nil];
    activity.completionWithItemsHandler= ^(NSString *activityType, BOOL completed, NSArray *returnedItems, NSError *activityError) {
        NSLog(@"activityType --------%@",activityType);
        //activityType --------com.tencent.xin.sharetimeline
    };
    activity.title=@"系统分享";
    if([activity respondsToSelector:@selector(popoverPresentationController)])
    {
        activity.popoverPresentationController.sourceView=ipadPopView;
        activity.popoverPresentationController.permittedArrowDirections=UIPopoverArrowDirectionDown;
        [viewController presentViewController:activity animated:YES completion:nil];
    }else
    {
        [viewController presentViewController:activity animated:YES completion:nil];
    }
    return YES;
}```

你可能感兴趣的:(Objective-c 不调用微信api 直接调用系统微信分享)