简体   繁体   English

iOS 8上的Facebook登录; 登录切换后,应用无法运行

[英]Facebook Login on iOS 8; App doesn't work after login switch

I'm using the latest FBSDKLoginKit (4.10.1) to let my users authenticate with Facebook. 我正在使用最新的FBSDKLoginKit(4.10.1)让我的用户通过Facebook进行身份验证。 It works perfectly on iOS 9, but not on iOS 8. When the user authenticates, the app switches to either the native facebook app or safari to log in. When logged in, the app switches back to my app, but then nothing happens. 它可以在iOS 9上完美运行,但不能在iOS 8上正常运行。当用户进行身份验证时,该应用程序切换到本机Facebook应用程序或野生动物园以登录。登录后,该应用程序切换回我的应用程序,但是什么也没有发生。 The handler block isn't executed. 处理程序块未执行。 Exact the same code works on iOS 9, but not on 8. I noticed that when my app switches to safari to authenticate, the debugger of xcode detaches from the simulator; 完全相同的代码可以在iOS 9上运行,但不能在8上运行。我注意到,当我的应用切换到Safari进行身份验证时,xcode的调试器会与模拟器分离; so I can't spot any errors. 所以我找不到任何错误。 This doesn't happen on iOS 9. 在iOS 9上不会发生这种情况。

This is my code to login: 这是我要登录的代码:

@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
    })
}

This is my info.plist: 这是我的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>

And this is my appdelegate: 这是我的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])
    {

    }
}

I guess something is wrong with my appdelegate, because I think my app doesn't recognize the back-switch from safari/FB native to my app. 我猜我的appdelegate出了点问题,因为我认为我的应用无法识别从Safari / FB本机向我的应用的反向切换。 The strange thing is that everything works just fine in iOS 9! 奇怪的是,一切在iOS 9中都可以正常工作!

  • With 'working on iOS 9' I mean it works running on a device on iOS 9. I'm compiling with iOS SDK 9.2. “在iOS 9上工作”是指它可以在iOS 9上的设备上运行。我正在使用iOS SDK 9.2进行编译。

As I stated in the comments above: 正如我在上面的评论中所述:

(Yes,) I deleted UIApplicationExitsOnSuspend from the plist. (是的)我从plist中删除了UIApplicationExitsOnSuspend。 This line made my app 'reset' everytime the app switched to Safari and back. 每当应用程序切换到Safari并返回时,此行都会使我的应用程序“重置”。 That's why the debugger got detached also. 这就是调试器也脱离的原因。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM