如何在Facebook上分享IOS应用程序的产品详细信息

时间:2017-07-25 05:08:14

标签: ios objective-c fbsdksharekit

我正在制作基于在线购物的应用程序。我想创建一个功能,在Facebook上发布我的产品详细信息。谁能告诉我如何实现这一目标呢?

当用户按分享按钮时,我想在fb中自动分享产品详细信息。

3 个答案:

答案 0 :(得分:6)

我认为您已经拥有了产品图片及其详细信息。所以Facebook提供了一个SKD,只需点击一下按钮就可以分享您的产品信息。此外,当用户点击您的帖子时,您也可以让用户重定向到您的链接。

有关FBSDKShareKit的更多信息,请仔细阅读 FB for developers link

以下是用于分享您的产品信息并在用户点击时将用户发送到您的网页的代码,

只需在您的分享按钮方法中编写此代码。

 FBSDKShareLinkContent *content =[[FBSDKShareLinkContent alloc] init];
content.contentURL = [NSURL URLWithString:@"your product page URL here"];
content.imageURL = [NSURL URLWithString:@"your product image url here"];
content.contentTitle= @"Title of your product";
content.contentDescription=@"Description of your product";
FBSDKShareDialog *dialog=[[FBSDKShareDialog alloc]init];
dialog.mode=FBSDKShareDialogModeNative;
if (![dialog canShow]) {
    // fallback presentation when there is no FB app
    dialog.mode = FBSDKShareDialogModeWeb;
    //
}
dialog.shareContent=content;
dialog.delegate=self;
dialog.fromViewController=self;
[dialog show];

确保在.h文件中导入FBSDKCoreKit / FBSDKCoreKit.h和FBSDKShareKit / FBSDKShareKit.h并将代理添加到其中。

答案 1 :(得分:3)

iOS 11更新

Facebook应用已删除TwitterSettings和其他应用选项。

使用iOS sharing extensions

,现在可以像使用其他应用一样对待这些应用
let share = [image, text, url]
let activityViewController = UIActivityViewController(activityItems: share, applicationActivities: nil)
activityViewController.popoverPresentationController?.sourceView = self.view
self.present(activityViewController, animated: true, completion: nil)

您还可以使用第三方SDK进行个人共享

Facebook Sharing Doc

Twitter Sharing Doc

=============================================== ===========================

您可以使用Social Framework分享帖子。你也可以在twitter上分享。

enter image description here

目标C

#import <Social/Social.h>


if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {
    SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];

    [controller setInitialText:@"First post from my iPhone app"];
    [self presentViewController:controller animated:YES completion:Nil];        
}

<强> SWIFT

import Social

let vc = SLComposeViewController(forServiceType:SLServiceTypeFacebook)
vc.add(imageView.image!)
vc.add(URL(string: "http://www.example.com/"))
vc.setInitialText("Initial text here.")
self.present(vc, animated: true, completion: nil)

更多详情Facebook and twitter sharing

答案 2 :(得分:1)

使用SLComposeViewController显示本机对话框&amp;在Facebook上发布您的内容。

 if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {

    __weak CFShareToFacebookViewController *weakSelf = self;

        SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];

        [controller setInitialText:self.captionTextField.text];
        [controller addURL:[NSURL URLWithString:@"http://www.google.com"]];
        [controller addImage:self.selectedImage];
        [controller setCompletionHandler:^(SLComposeViewControllerResult result) {

          switch (result) {
            case SLComposeViewControllerResultCancelled:
              break;
            case SLComposeViewControllerResultDone: {

            }
              break;

            default:
              break;
          }
        }];

        [self presentViewController:controller animated:YES completion:Nil];

  }