簡體   English   中英

iOS中的Facebook分享

[英]Facebook Sharing in iOS

我在我的應用程序中實現了Facebook共享。

FBSDKShareLinkContent *content=[[FBSDKShareLinkContent alloc]init];
        [content setContentDescription:theDescription];
        [content setContentTitle:theTitle];
        //[content setContentURL:[NSURL URLWithString:itemURL]];
       // content.contentURL = [NSURL URLWithString:@"http://developers.facebook.com"];
       [content setImageURL:[NSURL URLWithString:imageURL]];
    [FBSDKShareDialog showFromViewController:self withContent:content delegate:self];

但是“共享”對話框顯示為空。 為什么不顯示/張貼我設置的標題和描述?

共享視圖的文本未預填寫,因為Facebook不允許您這樣做。 當鏈接顯示在Facebook上時使用內容描述和標題,這與共享措辭不同。

試試看

FBSDKShareDialog *shareDialog = [[FBSDKShareDialog alloc] init];
FBSDKShareLinkContent *content = [[FBSDKShareLinkContent alloc]init];
[content setContentDescription:theDescription];
[content setContentTitle:theTitle];
[content setImageURL:[NSURL URLWithString:imageURL]];

[shareDialog setMode:FBSDKShareDialogModeAutomatic];
[shareDialog setShareContent:content];
[shareDialog setFromViewController:self];
[shareDialog show];

你可以試試這個(Objective-C)嗎? 在Swift中,對我來說效果很好:

func shareLinks(title:String, imageUrl:String, contentUrl:String, vc:UIViewController){
        var fbcontent = FBSDKShareLinkContent()
        //Valid url that contains any content
        fbcontent.contentURL = NSURL(string: contentUrl)
        //Title of this post
        fbcontent.contentTitle = title
        //Image will be displayed in timeline with this post
        fbcontent.imageURL = NSURL(string: imageUrl)
        dialog.shareContent = fbcontent
        dialog.fromViewController = vc
        dialog.mode = FBSDKShareDialogMode.Automatic
        dialog.show()
    }

如果你分享這個

[NSURL URLWithString:@"http://developers.facebook.com"];

共享對話框顯示為空嗎?

如果不是,則必須知道共享頁面上必須有OPEN GRAPH信息。

供共享圖片使用

FBSDKSharePhoto *photo = [[FBSDKSharePhoto alloc] init];
  photo.image = image;
  photo.userGenerated = YES;
  photo.caption=@"Some text";
  FBSDKSharePhotoContent *content = [[FBSDKSharePhotoContent alloc] init];
  content.photos = @[photo];

您可以使用SLComposer作為替代

對於FBSDK 4.12.0版本:

Facebook鏈接共享工作如下:

 FBSDKShareLinkContent *content =[[FBSDKShareLinkContent alloc] init];
 content.contentURL = [NSURL URLWithString:songUrl];
 content.imageURL = [NSURL URLWithString:artWorkURL];
 content.contentTitle= [NSString stringWithFormat: @"%@", trackName];
 content.contentDescription=[NSString stringWithFormat:@"Some text"];
 [FBSDKShareDialog showFromViewController:self withContent:content delegate:self];

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM