简体   繁体   中英

How to share product details from IOS app in Facebook

I am making a online shopping based App. I want to create a functionality to post my product details in Facebook. Can anyone tell me how I can achieve this?

I want to share product details automatically in fb when the user press share button.

I think you already have your product image and the detail information about it. So Facebook provides an SKD where you can share your product information from just one click of button. And also u can make users to redirect to your link when the users click on your post.

for more information about FBSDKShareKit please go through this FB for developers link

Here is the code for sharing your product info and sending users to your page when they click on it,

just write this code in your method of share button.

 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];

make sure you import FBSDKCoreKit/FBSDKCoreKit.h and FBSDKShareKit/FBSDKShareKit.h in your .h file and add the delegates to it.

iOS 11 Update

The Facebook , Twitter , and Other apps options have been removed in the Settings app.

That apps will now be treated like other apps, using the 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)

You can also use third party SDK for individual sharing

Facebook Sharing Doc

Twitter Sharing Doc

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

You can sharing post using Social Framework . you can also sharing on twitter.

在此输入图像描述

OBJECTIVE 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)

More Details Facebook and twitter sharing

Use SLComposeViewController to display native dialog box & post your content on 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];

  }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM