我正在尝试在 iOS9 中使用 Parse 登录 Facebook,但应用程序在真实设备中继续打开 Safari 而不是 Facebook 应用程序。甚至在 Safari 中,当我尝试使用键盘输入 Facebook 帐户的电子邮件和密码时,页面会重新加载,因此无法登录并授予该应用程序权限。用户应该先打开 safari 并登录 Facebook,然后打开我的应用程序,然后授予权限。我认为这不是最好的用户体验,因为用户已经拥有 Facebook 应用程序。
我已按照我将在此处列出的所有步骤进行操作:
更新了 info.plist
<key>CFBundleURLTypes</key> <array> <dict> <key>CFBundleURLSchemes</key> <array> <string>fb907580375984874</string> </array> </dict> </array> <key>CFBundleVersion</key> <string>1</string> <key>FacebookAppID</key> <string>907580375984874</string> <key>FacebookDisplayName</key> <string>Appname</string> <key>LSApplicationQueriesSchemes</key> <array> <string>fbapi</string> <string>fbapi20130214</string> <string>fbapi20130410</string> <string>fbapi20130702</string> <string>fbapi20131010</string> <string>fbapi20131219</string> <string>fbapi20140410</string> <string>fbapi20140116</string> <string>fbapi20150313</string> <string>fbapi20150629</string> <string>fbauth</string> <string>fbauth2</string> <string>fb-messenger-api20140430</string> </array> <key>LSRequiresIPhoneOS</key> <true/> <key>NSAppTransportSecurity</key> <dict> <key>NSExceptionDomains</key> <dict> <key>akamaihd.net</key> <dict> <key>NSExceptionRequiresForwardSecrecy</key> <false/> <key>NSIncludesSubdomains</key> <true/> </dict> <key>facebook.com</key> <dict> <key>NSExceptionRequiresForwardSecrecy</key> <false/> <key>NSIncludesSubdomains</key> <true/> </dict> <key>fbcdn.net</key> <dict> <key>NSExceptionRequiresForwardSecrecy</key> <false/> <key>NSIncludesSubdomains</key> <true/> </dict> </dict> </dict>
应用委托(delegate)
import UIKit import Parse import FBSDKCoreKit import ParseFacebookUtilsV4 @UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { Parse.setApplicationId("appID", clientKey: "MyKey") PFFacebookUtils.initializeFacebookWithApplicationLaunchOptions(launchOptions) return true } func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject) -> Bool { return FBSDKApplicationDelegate.sharedInstance().application(application,openURL: url,sourceApplication: sourceApplication, annotation: annotation) } func applicationDidBecomeActive(application: UIApplication) { FBSDKAppEvents.activateApp() }
登录码:
@IBAction func loginButtonClicked(sender: AnyObject) { if let _ = FBSDKAccessToken.currentAccessToken() { print("connected already") } else { PFFacebookUtils.logInInBackgroundWithReadPermissions(["public_profile", "email", "user_friends", "user_birthday" , "user_education_history","user_photos"]) { (user: PFUser?, error: NSError?) -> Void in if let user = user { if user.isNew { print("User signed up and logged in through Facebook!") } else { print("User logged in through Facebook!") } } else { print("Uh oh. The user cancelled the Facebook login.") } } }
最佳答案
现在使用 webview 登录用户是 iOS 9 的 Facebook SDK 的默认行为,根据 Facebook 团队的说法,这种方法提供了更好的用户体验,因为它避免了在应用程序转换之间显示额外的对话。
In apps that use the newest SDK (v4.6 and v3.24), we will surface a flow using Safari View Controller (SVC) instead of fast-app-switching (FAS) because of additional dialog interstitials that add extra steps to the login process in FAS on iOS 9. Additionally, data that we've seen from more than 250 apps indicate that this is the best experience for people in the long run
关于ios - 在 iOS9 和 Swift2 中使用 Parse 登录 Facebook,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33423180/