Reputation: 41
I'm writing an iOS app to do photo sharing.
Using technology Swift and FBSDK 4.0.1
I found that photo sharing by FBSDKSharePhotoContent()
CANNOT get back any post id from result object in FBSDKSharingDelegate
inside method didCompleteWithResults
.
Result object contains empty row:
[:]
However, URL sharing by FBSDKShareLinkContent() can get back post id from the result object. something like that:
[postId: 10000844250000_146108069750000]
Part of my core code:
Image Picker Controller (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)
}
After choosing photo, click custom share button
@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")
}
I will appreciate your help.
Upvotes: 4
Views: 2078
Reputation: 1
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()
// Delegate Methods
func sharer(_ sharer: FBSDKSharing!, didCompleteWithResults results: [AnyHashable : Any]!) {
print("delegates called")
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")
}
with the above workaround you can access postId.
Upvotes: 0