如何使用facebook sdk在iphone上分享Facebook截图

时间:2014-07-30 16:33:11

标签: ios objective-c facebook facebook-graph-api

我对这个领域很新。任何请帮助分享应用程序截图到Facebook。我一直在尝试使用[FBDialogs presentShareDialogWithParams]分享屏幕截图,但之后只说FBLinkShareParams: only \"http\" or \"https\" schemes are supported for link thumbnails

我们如何在Facebook上分享ios设备的应用程序截图?

1 个答案:

答案 0 :(得分:2)

希望这有帮助

-(void)FBshareScreenshot{
    if ([FBDialogs canPresentShareDialogWithPhotos]) {
        FBPhotoParams *params = [[FBPhotoParams alloc] init];
        UIImage *screenshot = [self captureScreenshot]; //calling to capture screenshot
        params.photos = @[screenshot];
        [FBDialogs presentShareDialogWithPhotoParams:params
                                         clientState:nil
                                             handler:^(FBAppCall *call, NSDictionary *results, NSError *error) {

                                                 if(error) {
                                                     NSLog(@"Error publishing story = %@.", error);
                                                     NSLog(@"result = %@.", results);
                                                 } else if (results[@"completionGesture"] && [results[@"completionGesture"] isEqualToString:@"cancel"]) {
                                                     NSLog(@"User canceled photo publishing.");
                                                 } else {
                                                     NSLog(@"photo posted");
                                                 }
                                             }];
    }else {
       //The user doesn't have the Facebook for iOS app installed, so we can't present the Share Dialog
       /*Fallback: You have two options
         1. Share the photo as a Custom Story using a "share a photo" Open Graph action, and publish it using API calls.
         See our Custom Stories tutorial: https://developers.facebook.com/docs/ios/open-graph
         2. Upload the photo making a requestForUploadPhoto
         See the reference: https://developers.facebook.com/docs/reference/ios/current/class/FBRequest/#requestForUploadPhoto:
         */
    }
}


-(UIImage *)captureScreenshot{
    UIGraphicsBeginImageContext(self.view.bounds.size);
    [self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *imageView = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
  //  UIImageWriteToSavedPhotosAlbum(imageView, nil, nil, nil);
    return imageView;
}