0

我刚开始在 iOS 上使用 Facebook idk,并希望允许用户从我的应用程序中共享图像、标题和描述,如下所示:

在此处输入图像描述

但我只得到标题和描述:s 这是我的代码:

let imageType: FBSDKSharePhoto = FBSDKSharePhoto(image: self.GenerateMapImage("\(latitude)",lng: "\(longitude)") , userGenerated: false)
            //let imageType2: FBSDKSharePhoto = FBSDKSharePhoto(image: UIImage(named: alertObj.id) , userGenerated: false)
            //
            imageType.caption = alertObj.alertType[0].name

            let content: FBSDKShareOpenGraphContent = FBSDKShareOpenGraphContent()
            let contentProp = ["og:type":"name_space:alert","og:title":"#\(name) \(addressName)","og:url" : "http://www.url.com"  , "og:description": description, "place:location:latitude":"\(latitude)", "place:location:longitude":"\(longitude)", "name_space:location:latitude":"\(latitude)", "name_space:location:longitude":"\(longitude)", "og:data:name_space:location:latitude":"\(latitude)", "og:data:name_space:location:longitude":"\(longitude)", "al:web:url" : "http://www.url.com"  ]

            let graphObj: FBSDKShareOpenGraphObject = FBSDKShareOpenGraphObject(properties: contentProp)
            graphObj.setArray([imageType], forKey: "og:image")

           // graphObj.setPhoto(imageType, forKey: "og:image")

            let facebookShare:FBSDKShareDialog = FBSDKShareDialog()
            let fbAction: FBSDKShareOpenGraphAction = FBSDKShareOpenGraphAction()
            facebookShare.delegate = alertActionsIntance
            fbAction.setArray([imageType], forKey: "og:image")
            fbAction.setObject(graphObj, forKey: "alert")
            fbAction.actionType = "name_space:share"

            content.action = fbAction
            content.previewPropertyName = "alert"

            facebookShare.mode = FBSDKShareDialogMode.Automatic
            facebookShare.shareContent = content;
            facebookShare.fromViewController = alertController;
            facebookShare.show()

这也是我的应用程序配置:

对象配置 附件

4

1 回答 1

0

我在使用时遇到了类似的问题FBSDKSharePhoto。如果您可以使用图像 url,只需将其作为字符串条目放入您的contentProp字典"og:image":IMAGE_URL中,它将显示为缩略图。

这对我有用

NSDictionary *properties  = @{
                                 @"og:type": @"",
                                 @"og:title":@"",
                                 @"og:description": @"",
                                 @"og:url":@"",
                                 @"og:image":@""
                            };


}
//Create an object
FBSDKShareOpenGraphObject *object = [FBSDKShareOpenGraphObject objectWithProperties:properties];
// Create an action
FBSDKShareOpenGraphAction *action = [[FBSDKShareOpenGraphAction alloc] init];
action.actionType = @"";
[action setObject:object forKey:@""];

// Create the content
FBSDKShareOpenGraphContent *content = [[FBSDKShareOpenGraphContent alloc] init];
content.action = action;
content.previewPropertyName = @"";

[FBSDKShareDialog showFromViewController:self
                             withContent:content
                                delegate:self];
于 2016-03-22T15:03:22.103 回答