Share With Facebook Not Working Anymore on iOS 11

限于喜欢 提交于 2019-11-30 20:21:39

问题


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.


回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/46396524/share-with-facebook-not-working-anymore-on-ios-11

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!