ios - iOS 8 上的 Facebook 登录;登录切换后应用程序无法运行

标签 ios swift facebook facebook-login fbsdk

我正在使用最新的 FBSDKLoginKit (4.10.1) 让我的用户通过 Facebook 进行身份验证。它在 iOS 9 上完美运行,但在 iOS 8 上运行不佳。当用户进行身份验证时,应用程序切换到 native facebook 应用程序或 safari 以登录。登录后,应用程序切换回我的应用程序,但随后没有任何反应。处理程序 block 未执行。完全相同的代码适用于 iOS 9,但不适用于 8。我注意到当我的应用程序切换到 safari 进行身份验证时,xcode 的调试器与模拟器分离;所以我无法发现任何错误。这不会发生在 iOS 9 上。

这是我的登录代码:

@IBAction func login(sender: AnyObject) {

    let facebookLogin = FBSDKLoginManager()

    facebookLogin.logInWithReadPermissions(["public_profile", "email", "user_friends"], fromViewController: self, handler: {
        (facebookResult, facebookError) -> Void in

        // some logic which isn't executed
    })
}

这是我的 info.plist:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>CFBundleDevelopmentRegion</key>
    <string>en</string>
    <key>CFBundleExecutable</key>
    <string>$(EXECUTABLE_NAME)</string>
    <key>CFBundleIdentifier</key>
    <string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
    <key>CFBundleInfoDictionaryVersion</key>
    <string>6.0</string>
    <key>CFBundleName</key>
    <string>$(PRODUCT_NAME)</string>
    <key>CFBundlePackageType</key>
    <string>APPL</string>
    <key>CFBundleShortVersionString</key>
    <string>0.1</string>
    <key>CFBundleSignature</key>
    <string>????</string>
    <key>CFBundleURLTypes</key>
    <array>
        <dict>
            <key>CFBundleURLSchemes</key>
            <array>
                <string>fb190918247921312</string>
            </array>
        </dict>
    </array>
    <key>CFBundleVersion</key>
    <string>5</string>
    <key>FacebookAppID</key>
    <string>190918247921312</string>
    <key>FacebookDisplayName</key>
    <string>RegelBaas</string>
    <key>LSRequiresIPhoneOS</key>
    <true/>
    <key>NSAppTransportSecurity</key>
    <dict>
        <key>NSExceptionDomains</key>
        <dict>
            <key>akamaihd.net</key>
            <dict>
                <key>NSIncludesSubdomains</key>
                <true/>
                <key>NSThirdPartyExceptionRequiresForwardSecrecy</key>
                <false/>
            </dict>
            <key>facebook.com</key>
            <dict>
                <key>NSIncludesSubdomains</key>
                <true/>
                <key>NSThirdPartyExceptionRequiresForwardSecrecy</key>
                <false/>
            </dict>
            <key>fbcdn.net</key>
            <dict>
                <key>NSIncludesSubdomains</key>
                <true/>
                <key>NSThirdPartyExceptionRequiresForwardSecrecy</key>
                <false/>
            </dict>
        </dict>
    </dict>
    <key>UIAppFonts</key>
    <array>
        <string>Stackyard_PERSONAL_USE.ttf</string>
    </array>
    <key>UIApplicationExitsOnSuspend</key>
    <true/>
    <key>UILaunchStoryboardName</key>
    <string>LaunchScreen</string>
    <key>UIMainStoryboardFile</key>
    <string>Main</string>
    <key>UIRequiredDeviceCapabilities</key>
    <array>
        <string>armv7</string>
    </array>
    <key>UISupportedInterfaceOrientations</key>
    <array>
        <string>UIInterfaceOrientationPortrait</string>
    </array>
    <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>
</dict>
</plist>

这是我的 appdelegate:

//
//  AppDelegate.swift
//  RegelBaas
//
//  Created by J. Weijland on 12-12-15.
//  Copyright © 2015 J. Weijland. All rights reserved.
//

import UIKit
import FBSDKCoreKit
import FBSDKLoginKit
import Batch

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?

    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
        // Styling

        UINavigationBar.appearance().barTintColor = UIColor(red: 1.0, green: (102/255), blue: (102/255), alpha: 1)

        UINavigationBar.appearance().tintColor = UIColor.whiteColor()

        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, openURL: url, sourceApplication: sourceApplication, annotation: annotation)
    }

    func applicationDidBecomeActive(application: UIApplication) {
        // 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.
        FBSDKAppEvents.activateApp()
    }

    func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject])
    {

    }
}

我猜我的 appdelegate 有问题,因为我认为我的应用程序无法识别从 safari/FB 原生到我的应用程序的后退切换。奇怪的是在 iOS 9 中一切正常!

  • “在 iOS 9 上运行”是指它可以在运行 iOS 9 的设备上运行。我正在使用 iOS SDK 9.2 进行编译。

最佳答案

正如我在上面的评论中所说:

(Yes,) I deleted UIApplicationExitsOnSuspend from the plist. This line made my app 'reset' everytime the app switched to Safari and back. That's why the debugger got detached also.

关于ios - iOS 8 上的 Facebook 登录;登录切换后应用程序无法运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36489689/

相关文章:

objective-c - NSMutableArray 有 500 个对象。

ios - 自定义标注 View 按钮到 map

ios - 登录 Facebook FBSDK 输入错误代码 : 308 in Swift 4. 2

javascript - 为什么以下 Facebook 分享按钮没有打开弹出窗口?

facebook - 使用 facebook javascript sdk 发布到 friend 墙

ios - 更改不相关 View 的 z 顺序

objective-c - 当我将 UINavigationController 放入 UIPopoverController 中时,navigationBar 不显示

ios - 从字符串优化中提取链接

facebook - 如何通过调用 Graph API 获取 facebook 用户元数据?

ios - widgetURL 在 Foreach 内被覆盖?