分享与Facebook在iOS 11上不再工作 [英] Share With Facebook Not Working Anymore on iOS 11
问题描述
我使用Facebook SDK对于iOS,它在iOS 10上工作正常,但当我将手机升级到iOS 11时,facebook分享不再有用了。请提前帮助。
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.
推荐答案
不幸的是,iOS 11更新了社交网络服务(Facebook,Twitter,Vimeo和Flickr)曾经用于系统范围集成的单点登录已被删除。
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 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)
你可以使用 FBSDKGraphRequest 。
首先从Facebook Developer Console创建您的应用程序。之后,设置您的Xcode项目(按照此处的说明进行操作: https://developers.facebook.com/docs/ios/getting -started / )。
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")
}
}
记录后保存令牌并使用它通过FBSDKGraphRequest发布消息:
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!")
}
})
希望这有帮助。
这篇关于分享与Facebook在iOS 11上不再工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!