IOS 9 Swift - 解析Facebook登录无法打开原生Facebook应用程序

9

我已经将Parse框架与所有Facebook依赖项集成到我的应用程序中。我的plist配置如下:

<key>CFBundleURLTypes</key>
    <array>
        <dict>
            <key>CFBundleURLSchemes</key>
            <array>
                <string>fbXXXXXXXXXXXXX</string>
            </array>
        </dict>
    </array>
    <key>FacebookAppID</key>
    <string>XXXXXXXXXXXXX</string>
    <key>FacebookDisplayName</key>
    <string>XXXXX</string>

    <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>

    <key>LSApplicationQueriesSchemes</key>
    <array>
        <string>fbauth2</string>
    </array>

我的登录代码如下:

PFFacebookUtils.logInInBackgroundWithReadPermissions(permissionsArray, block: { (user, error) -> Void in
            if(error != nil){
                print("Login failed")
            }else{
                if let currentUser = user{
                    if(currentUser.isNew){
                        print("New user")
                    }else{
                        print("Login success")
                    }
                }else{
                    print("Login canceled")
                }

            }
        })

一切正常,但登录过程是在Safari中进行的,而不是已安装的Facebook应用程序。

我错过了什么?


试一下这个:http://stackoverflow.com/questions/33315083/error-in-facebook-login-ios-9-swift - Lukesivi
1个回答

5
自 iOS 9 起,Facebook SDK 不再提供通过 Facebook 应用程序的授权。原因在于在应用打开其他应用之前会提示用户,这会影响用户体验。
您唯一的选择是使用 FBSDKLoginBehaviorSystemAccountFBSDKLoginBehaviorBrowser
PFFacebookUtils.facebookLoginManager().loginBehavior = FBSDKLoginBehavior.SystemAccount

谢谢你的回复。然而,我可以看到其他应用程序成功地使用了这种方法(比如AirBnB)。我尝试过添加 (PFFacebookUtils.facebookLoginManager()).loginBehavior = FBSDKLoginBehavior.SystemAccount 但没有成功。还有其他的想法吗? - Shlomi Schwartz
您可以始终使用旧版SDK来恢复FBSDKLoginBehavior.Native,但是这并不推荐。为了让FBSDKLoginBehavior.SystemAccount正常工作,需要在iOS设置中设置FB,否则它会回退到浏览器模式。 - Armands L.
请问您能详细说明需要配置哪些设置吗?我在IOS平台上唯一设置的是Bundle ID。另外,.Native具有相同的效果。 - Shlomi Schwartz
要配置 Info.plist,请参阅FB文档此处。Bundle ID和启用单点登录就足够了。 - Armands L.

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接