在swift中,我添加了Facebook登录信息。这些是我的代表:
func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
return FBSDKApplicationDelegate.sharedInstance().application(app,open: url,sourceApplication: options[UIApplicationOpenURLOptionsKey.sourceApplication] as! String, annotation: options[UIApplicationOpenURLOptionsKey.annotation])
}
func applicationDidBecomeActive(_ application: UIApplication) {
FBSDKAppEvents.activateApp()
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
FIRApp.configure()
IQKeyboardManager.sharedManager().enable = true
FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)
return true
}
单击登录按钮时会调用此函数:
@IBAction func facebookLogin(_ sender: Any) {
let facebookLogin = FBSDKLoginManager()
print("Logging In")
facebookLogin.logIn(withReadPermissions: ["email", "public_profile", "user_friends"], from: self, handler:{(facebookResult, facebookError) -> Void in
if facebookError != nil { print("Facebook login failed. Error \(facebookError)")
} else if (facebookResult?.isCancelled)! { print("Facebook login was cancelled.")
} else { print("Logged in")}
});
}
但是,我从未看到登录,但我确实看到登录。
其他代码:
loginButton.readPermissions = ["email", "public_profile", "user_friends"]
loginButton.delegate = self
我已经将UIButtons类设置为FBSDKLoginButton
我刚登录时也不会在viewDidLoad()中打印:
if (FBSDKAccessToken.current() != nil)
{
print("user already logged in")
}
我试过了: Facebook login - stays at white web page SWIFT 和Facebook Authentication - Blank white screen during authentication - iOS 10 GM, Swift 3
然而答案对我不起作用。在获得许可后,safari会加载一个空白页面,之后不会执行任何操作。如何在获得许可后将用户重定向到我的应用程序?