关闭

iOS自带的分享功能

274人阅读 评论(0) 收藏 举报


方法一

添加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];
}

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:9264次
    • 积分:284
    • 等级:
    • 排名:千里之外
    • 原创:17篇
    • 转载:4篇
    • 译文:0篇
    • 评论:0条