简体   繁体   English

在iOS 11上与Facebook分享不再可用

[英]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. 我使用适用于iOS的Facebook SDK,它在iOS 10上运行良好,但是当我将手机升级到iOS 11时,facebook共享不再起作用。 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. 不幸的是,随着iOS 11更新,社交网络服务(Facebook,Twitter,Vimeo和Flickr)已被删除,该社交网络服务以前具有用于系统范围集成的单点登录。

Instead to use this snippet for iOS 10 and before : 而是在iOS 10及更低版本中使用此代码段

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 . 您可以使用 FBSDKGraphRequest 在Facebook上 发布

First create from Facebook Developer Console your app. 首先从Facebook Developer Console创建您的应用程序。 After that, setup your Xcode project (following the instructions here: https://developers.facebook.com/docs/ios/getting-started/ ). 之后,设置您的Xcode项目(按照此处的说明进行操作: 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发布消息:

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. 带有Facebook Share的iOS 11(在我的情况下为Objective-c中的FBSDKShareDialog)的此问题已通过升级到最新的Facebook API框架得以解决。 Via pods, that is currently as follows: 通过pod,当前如下所示:

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 例如,播客搜索FBSDKShareKit

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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