如何在iOS上嵌入Facebook共享,就像附加图片一样

时间:2015-09-21 10:07:55

标签: ios facebook facebook-ios-sdk

我遇到了一个应用程序,我真的很想知道他们在Facebook上分享了什么。

该应用程序显示一个打开窗口的共享按钮(见下图)。共享对话框的共享参数是一个图像和一个URL,这意味着当我将它发布到我的墙上时,谁将点击它将输入输入的URL。

有谁知道怎么做?

enter image description here

2 个答案:

答案 0 :(得分:3)

您可以使用原生SLComposeViewController执行此操作。 只需添加社交媒体框架。在项目中导入,然后添加以下行:

- (IBAction)facebookPost:(id)sender {

    if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {

        SLComposeViewController *mySLComposerSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];

        [mySLComposerSheet setInitialText:@"Social Framework sharing test!"];

        [mySLComposerSheet addImage:[UIImage imageNamed:@"myImage.png"]];

        [mySLComposerSheet addURL:[NSURL URLWithString:@"http://stackoverflow.com/questions/32692493/how-to-embed-facebook-share-on-ios-like-at-attached-pic"]];

        [mySLComposerSheet setCompletionHandler:^(SLComposeViewControllerResult result) {

             switch (result) {
                 case SLComposeViewControllerResultCancelled:
                     NSLog(@"Post Canceled");
                     break;
                 case SLComposeViewControllerResultDone:
                     NSLog(@"Post Sucessful");
                     break;

                 default:
                     break;
             }
         }];

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

答案 1 :(得分:1)

I have a same issue.

This is caused by below situation.

1 To post both "Image" and "URL". (using these methods => addImage: addUrl: )

2 To be downloaded Facebook App in your iPhone, and login through the Facebook App. (if your iPhone has not Facebook App, it doesn't occur.)

I think this is caused by Facebook account's setting.

I have a multiple Facebook test accounts. An Facebook test account cause this phenomenon.And switch another facebook account, it doesn't cause this phenomenon.So I guess this is caused by Facebook account's setting.

If you want to post Correctly , there are two ways.

1 Delete Facebook App on your iPhone, and login through device setting Facebook Account.

2 Give up that to post both "image" and "URL". If you post only one(image or URL),you can post Correctly.

I hope this helps :)