我正在使用 Swift 3.0 集成 Facebook SDK 4.15.1。
我已按照链接中提到的所有步骤进行操作
Getting started with iOS ,我可以登录 Facebook 并使用 Safari 浏览器进行授权,但之后该控件没有返回到我的应用程序并显示空白页面。但是当我按下完成按钮时,委托(delegate)方法 didCompleteWith 结果: 被调用并出现错误 OAuthException 。在我的应用程序中也永远不会调用 OpenURL 方法。我还彻底验证了我的属性列表文件和应用程序 ID,包标识符或应用程序 ID 没有错误。
在设备 < iOS 9.0 中不显示空白页。
感谢任何帮助。
以下是我在 Swift 3.0 中用于登录和获取访问 token 的代码,
AppDelegate.swift
import UIKit
import CoreData
import FBSDKCoreKit
import FBSDKLoginKit
import FBSDKShareKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, GIDSignInDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)
return true
}
func application(application: UIApplication,
openURL url: NSURL, sourceApplication: String?, annotation: AnyObject) -> Bool {
return FBSDKApplicationDelegate.sharedInstance().application(application, open: url as URL!, sourceApplication: sourceApplication, annotation: annotation)
}
func applicationDidBecomeActive(_ application: UIApplication) {
FBSDKAppEvents.activateApp()
}
ViewController.swift
import UIKit
import FBSDKLoginKit
import FBSDKCoreKit
class ViewController: UIViewController, GIDSignInUIDelegate, FBSDKLoginButtonDelegate {
public func loginButtonDidLogOut(_ loginButton: FBSDKLoginButton!) {
}
let loginView : FBSDKLoginButton = FBSDKLoginButton()
self.view.addSubview(loginView)
loginView.center = self.view.center
loginView.readPermissions = ["public_profile", "email", "user_friends"]
loginView.delegate = self
}
func loginButton(_ loginButton: FBSDKLoginButton!, didCompleteWith result: FBSDKLoginManagerLoginResult!, error: Error!) {
if error == nil {
print("Success")
let graphRequest : FBSDKGraphRequest = FBSDKGraphRequest(graphPath: "me", parameters: ["fields":"id,interested_in,gender,birthday,email,age_range,name,picture.width(480).height(480)"])
graphRequest.start(completionHandler: { (connection, result, error) -> Void in
if ((error) != nil)
{
print("Error: \(error)")
}
else
{
print("fetched user: \(result)")
}
})
}else{
print("Failure")
}
}
Best Answer-推荐答案 strong>
我已通过在属性列表中添加以下传输安全 key 来解决此问题。
<key>NSAppTransportSecurity</key>
<dict>
<key>NSExceptionDomains</key>
<dict>
<key>facebook.com</key>
<dict>
<key>NSIncludesSubdomains</key>
<true/>
<key>NSExceptionRequiresForwardSecrecy</key>
<false/>
</dict>
<key>fbcdn.net</key>
<dict>
<key>NSIncludesSubdomains</key>
<true/>
<key>NSExceptionRequiresForwardSecrecy</key>
<false/>
</dict>
<key>akamaihd.net</key>
<dict>
<key>NSIncludesSubdomains</key>
<true/>
<key>NSExceptionRequiresForwardSecrecy</key>
<false/>
</dict>
</dict>
</dict>
关于ios - FBSDKLoginKit 在登录和确认页面后不重定向我的应用程序,我们在Stack Overflow上找到一个类似的问题:
https://stackoverflow.com/questions/39701394/
|