简体   繁体   中英

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. 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. 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; so I can't spot any errors. This doesn't happen on 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:

<?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.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. The strange thing is that everything works just fine in 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.

As I stated in the comments above:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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