我正在编写一个iOS应用来进行照片共享。
使用技术Swift和FBSDK 4.0.1
我发现FBSDKShare分享照片照片内容()
无法从方法FBSDKSharingDelegate
内的didCompleteWithResults
中的结果对象中获取任何帖子ID。
Result对象包含空行:
[:]
但是,FBSDKShare的
[postId: 10000844250000_146108069750000]
我核心代码的一部分:
图片选择器控制器(UIImagePickerControllerDelegate
,UINavigationControllerDelegate
)
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [NSObject : AnyObject]) {
var theImage:UIImage = info[UIImagePickerControllerOriginalImage] as! UIImage
uploadImage.image = theImage
self.dismissViewControllerAnimated(false, completion: nil)
}
选择照片后,点击自定义分享按钮
@IBAction func postButtonClick(sender: AnyObject) {
let photoContent = FBSDKSharePhotoContent()
let photo : FBSDKSharePhoto = FBSDKSharePhoto()
photo.image = uploadImage.image
photo.userGenerated = true
photoContent.photos = [photo]
FBSDKShareDialog.showFromViewController(self, withContent: photoContent, delegate:self)
}
Facebook FBSDKSharingDelegate
func sharer(sharer: FBSDKSharing!, didCompleteWithResults results: [NSObject: AnyObject])
{
println("sharer didCompleteWithResults, results.count\(results.count)")
println(results)
// still cannot get post id from photo upload
}
func sharer(sharer: FBSDKSharing!, didFailWithError error: NSError!) {
println("sharer NSError")
println(error.description)
}
func sharerDidCancel(sharer: FBSDKSharing!) {
println("sharerDidCancel")
}
感谢您的帮助。
答案 0 :(得分:0)
let photo = FBSDKSharePhoto()
photo.image = chosenImage
photo.isUserGenerated = false
let photoContent = FBSDKSharePhotoContent()
photoContent.photos = [photo]
let shareApiInstance = FBSDKShareAPI()
shareApiInstance.message = "customized facebook content"
shareApiInstance.shareContent = photoContent
shareApiInstance.delegate = self
shareApiInstance.share()
//委托方法
func sharer(_ sharer:FBSDKSharing!,didCompleteWithResults results:[AnyHashable:Any]!){
print(“代表叫”)
let resultsInfo = results as! [String : Any]
print(resultsInfo["postId"] as! String)
}
func sharer(_ sharer: FBSDKSharing!, didFailWithError error: Error!) {
print("sharer NSError")
print(error.localizedDescription)
}
func sharerDidCancel(_ sharer: FBSDKSharing!) {
print("sharerDidCancel")
}
通过上述解决方法,您可以访问postId。