Reputation: 143
I'm trying to post a photo to Facebook, and it works fine using the following code:
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [NSObject : AnyObject]) {
self.selectedImage = info[UIImagePickerControllerOriginalImage] as! UIImage
var photo = FBSDKSharePhoto()
photo.image = self.selectedImage
photo.userGenerated = true
var content = FBSDKSharePhotoContent()
content.photos = [photo]
self.dismissViewControllerAnimated(true, completion: nil)
shareDialog.fromViewController = self
shareDialog.shareContent = content
shareDialog.show()
}
However, this only works when the user has the facebook app downloaded. otherwise it does NOT open the web browser to share the photo, even though facebook state:
The Share Dialog switches to the native Facebook for iOS app, then returns control to your app after a post is published. If someone doesn't have Facebook app installed it will automatically falls back to a web-based dialog.
Any suggestions please ? answers appreciated, thank you.
Upvotes: 0
Views: 746
Reputation: 599
You can try this:
func postToFacebook(image: UIImage!) {
var SocialMedia :SLComposeViewController = SLComposeViewController(forServiceType: SLServiceTypeFacebook)
SocialMedia.completionHandler = {
result -> Void in
var getResult = result as SLComposeViewControllerResult;
switch(getResult.rawValue) {
case SLComposeViewControllerResult.Cancelled.rawValue: println("Cancelled")
case SLComposeViewControllerResult.Done.rawValue: println("It's Work!")
default: println("Error!")
}
self.dismissViewControllerAnimated(true, completion: nil)
}
self.presentViewController(SocialMedia, animated: true, completion: nil)
SocialMedia.setInitialText("...")
SocialMedia.addImage(image)
}
Upvotes: 2