1. Add the class library file # import <social/social. h>
2. Click Sina Weibo to trigger the event
- (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]; } }
3. Click Twitter.
- (IBAction)shareToTwitter:(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:@"Twitter Message" message:output delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil]; [alert show]; } }]; if([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter]) { slComposerSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter]; [slComposerSheet setInitialText:self.sharingText]; [slComposerSheet addImage:self.sharingImage]; [slComposerSheet addURL:[NSURL URLWithString:@"http://www.twitter.com/"]]; [self presentViewController:slComposerSheet animated:YES completion:nil]; }}
Similar to Facebook, you only need to change enumeration.
4. Too many shares
- (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]; [self presentViewController:activityController animated:YES completion:nil];}
Demo: https://github.com/russj/ios6ShareDemo