[英]How to share product details from IOS app in Facebook
我正在制作基於在線購物的應用程序。 我想創建一個功能,在Facebook上發布我的產品詳細信息。 誰能告訴我如何實現這一目標?
我想在用戶按分享按鈕時自動在fb中分享產品詳細信息。
我想您已經擁有了產品圖片及其詳細信息。 所以Facebook提供了一個SKD,只需點擊一下按鈕就可以分享您的產品信息。 此外,當用戶點擊您的帖子時,您還可以讓用戶重定向到您的鏈接。
有關FBSDKShareKit的更多信息,請通過此FB獲取開發人員鏈接
以下是用於分享您的產品信息並在用戶點擊時將用戶發送到您的網頁的代碼,
只需在您的共享按鈕方法中編寫此代碼即可。
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並將代理添加到其中。
iOS 11更新
Facebook
, Twitter
和其他應用程序選項已在“ Settings
應用中刪除。
現在,應用程序將像其他應用程序一樣使用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
進行個人共享
================================================== ========================
您可以使用社交框架分享帖子。 你也可以在twitter上分享。
目標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];
}
迅速
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)
使用SLComposeViewController顯示本機對話框並在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];
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.