方法一
添加Social.framework至工程
-(IBAction)btnFacebookSharing_Clicked:(id)sender {
if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {SLComposeViewController * fbSheetOBJ = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[fbSheetOBJ setInitialText:@"Post from my iOS application"];
[fbSheetOBJ addURL:[NSURL URLWithString:@"http://www.weblineindia.com"]];
[fbSheetOBJ addImage:[UIImage imageNamed:@"my_image_to_share.png"]];
[self presentViewController:fbSheetOBJ animated:YES completion:Nil];
}
}
方法二
- (IBAction)sharingaction:(id)sender {
NSString *eventNameToShare = [NSString stringWithFormat:@"%@",_eventnameText];//要分享的标题
NSURL* bannerURL = [NSURL URLWithString:_bannerimageText];//要分享的图片链接
NSData* bannerdata = [[NSData alloc] initWithContentsOfURL:bannerURL];
UIImage *imageToShare = [UIImage imageWithData:bannerdata];
NSString *eventDetailToShare = [NSString stringWithFormat:@"%@",_eventdetailText];/要分享的具体文字
NSArray *itemsToShare = @[eventNameToShare, imageToShare, eventDetailToShare];
UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:itemsToShare applicationActivities:nil];
activityVC.excludedActivityTypes = @[UIActivityTypePrint, UIActivityTypeCopyToPasteboard, UIActivityTypeAssignToContact, UIActivityTypeSaveToCameraRoll]; //or whichever you don't need
[self presentViewController:activityVC animated:YES completion:nil];
}