iOS开发:Social.framework实现第三方分享

 

第三方汇总
(效果图)

- (IBAction)shareByActivity:(id)sender {
    NSArray *activityItems;

    if (self.sharingImage != nil) {
        activityItems = @[self.sharingText, self.sharingImage];
    } else {
        activityItems = @[self.sharingText];
    }

    UIActivityViewController *activityController =
    [[UIActivityViewController alloc] initWithActivityItems:activityItems
                                      applicationActivities:nil];
    [activityController setCompletionHandler:^(NSString *activityType, BOOL completed) {
        NSLog(@"start completion block %@",activityType);
        NSLog(@"completed %d",completed);

    }];
    [self presentViewController:activityController
                       animated:YES completion:nil];
}

分享到微博
- (IBAction)shareToWeibo:(id)sender {
    [slComposerSheet setCompletionHandler:^(SLComposeViewControllerResult result) {
        NSLog(@"start completion block");
        NSString *output;
        switch (result) {
            case SLComposeViewControllerResultCancelled:
                output = @"Action Cancelled";
                break;
            case SLComposeViewControllerResultDone:
                output = @"Post Successfull";
                break;
            default:
                break;
        }
        if (result != SLComposeViewControllerResultCancelled)
        {
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Weibo Message" message:output delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];
            [alert show];
        }
    }];

    if([SLComposeViewController isAvailableForServiceType:SLServiceTypeSinaWeibo])
    {
        slComposerSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeSinaWeibo];
        [slComposerSheet setInitialText:self.sharingText];
        [slComposerSheet addImage:self.sharingImage];
        [slComposerSheet addURL:[NSURL URLWithString:@"http://www.weibo.com/"]];
        [self presentViewController:slComposerSheet animated:YES completion:nil];
    }       
}
facebook和twitter同理

 

 

发表评论

*

* 绝不会泄露


Design By Inzaghi | 京ICP备16047555号-1