简体   繁体   中英

Share With Facebook Not Working Anymore on iOS 11

I Use Facebook SDK For iOS and its works fine on iOS 10 but when I upgrade my phone into iOS 11 the facebook share is not working anymore. please help, thanks in advance.

Unfortunately with the iOS 11 update the social network services (Facebook, Twitter, Vimeo, and Flickr), which used to have single sign-on for systemwide integration have been removed.

Instead to use this snippet for iOS 10 and before :

let viewController = SLComposeViewController(forServiceType: SLServiceTypeFacebook)
viewController.add(imageView.image!)
viewController.add(URL(string: "http://www.example.com/"))
viewController.setInitialText("Text to post!")

self.present(viewController!, animated: true, completion: nil)

You can post on Facebook using the FBSDKGraphRequest .

First create from Facebook Developer Console your app. After that, setup your Xcode project (following the instructions here: https://developers.facebook.com/docs/ios/getting-started/ ).

The user need to be logged before post:

    let login: FBSDKLoginManager = FBSDKLoginManager()
        login.logIn(withPublishPermissions: ["publish_actions"], from: self) { (result, error) in

            if (error != nil) {
                print("publish_actions: \(error!)")
            } else if (result?.isCancelled)! {
                print("publish_actions: Canceled")
            } else if (result?.grantedPermissions.contains("publish_actions"))! {
                print("publish_actions: permissions granted: \(String(describing: result?.token.tokenString))")

                UserDefaults.standard.set(result?.token.tokenString, forKey: "facebook_token")

            }

        }

After the logging save the token and use it to post a message through FBSDKGraphRequest:

FBSDKGraphRequest.init(graphPath: "me/feed",
                           parameters: ["message": "text to post on Facebook"],
                           tokenString: "token",
                           version: "v2.10",
                           httpMethod: "POST").start(completionHandler: { (connection, result, error) -> Void in
                            if let error = error {
                                print("Error: \(error)")
                            } else {
                                print("Posted successfully!")
                            }
                           })

Hope this help.

This problem for iOS 11 with Facebook Share (in my case, FBSDKShareDialog in Objective-c) is fixed by upgrading to the latest Facebook API frameworks. Via pods, that is currently as follows:

Podfile

  pod 'FBSDKCoreKit', '~> 4.27.0'
  pod 'FBSDKLoginKit', '~> 4.27.0'
  pod 'FBSDKShareKit', '~> 4.27.0'

From a command prompt, Using "pod search " will show the latest version of the pod. For example, pod search FBSDKShareKit

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM