ios - 在 iOS9 和 Swift2 中使用 Parse 登录 Facebook

标签 ios parse-platform swift2 facebook-ios-sdk

我正在尝试在 iOS9 中使用 Parse 登录 Facebook,但应用程序在真实设备中继续打开 Safari 而不是 Facebook 应用程序。甚至在 Safari 中,当我尝试使用键盘输入 Facebook 帐户的电子邮件和密码时,页面会重新加载,因此无法登录并授予该应用程序权限。用户应该先打开 safari 并登录 Facebook,然后打开我的应用程序,然后授予权限。我认为这不是最好的用户体验,因为用户已经拥有 Facebook 应用程序。

我已按照我将在此处列出的所有步骤进行操作:

  1. 添加 Fraleworks

    enter image description here

  2. 链接二进制文件

enter image description here

  1. 更新了 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>
    
    1. 应用委托(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()
      }
      

  2. 登录码:

    @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

Read more on Facebook

关于ios - 在 iOS9 和 Swift2 中使用 Parse 登录 Facebook,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33423180/

相关文章:

ios - 如何使 UITabBarItem 成为来自 unicode 的图像?

ios - Swift:使用 UISearchController/Predicates 过滤结构数组

iphone - 有没有办法从 ios 中的 mp3 中提取嵌入的图像数据

ios - 发送推送时iOS角标(Badge)不会增加

ios - 从指针访问另一个类列 - Parse

java - 这个类应该位于 JSP Web 应用程序的 ServletContext 或 session 范围内吗?

objective-c - tvOS:当按钮处于水平顺序时,将第一个按钮作为首选焦点 View

ios - 在 for-in 循环中更改数组的名称

firebase - 'FIRDatabaseReference' 的值类型没有成员 'observeSingleEvent'

ios - Xcode swift : How to change button font size dynamically according to the size of the button?