iOS 8 上的 Facebook 登录;登录切换后应用程序无法运行
Posted
技术标签:
【中文标题】iOS 8 上的 Facebook 登录;登录切换后应用程序无法运行【英文标题】:Facebook Login on iOS 8; App doesn't work after login switch 【发布时间】:2016-04-08 00:49:38 【问题描述】:我正在使用最新的 FBSDKLoginKit (4.10.1) 让我的用户通过 Facebook 进行身份验证。它在 ios 9 上完美运行,但在 iOS 8 上却不行。当用户进行身份验证时,应用程序切换到本机 facebook 应用程序或 safari 登录。登录后,应用程序切换回我的应用程序,但没有任何反应。处理程序块未执行。完全相同的代码适用于 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 进行编译。【问题讨论】:
你找到解决这个问题的办法了吗? 是的,我从 plist 中删除了<key>UIApplicationExitsOnSuspend</key> <true/>
。每次应用程序切换到 Safari 并返回时,这条线都会让我的应用程序“重置”。这就是调试器也被分离的原因。
我有同样的问题,但我在 plist 中没有这样的密钥。其他人有解决方案吗?它适用于 iOS 9 和 iOS10,但适用于 iOS8
【参考方案1】:
正如我在上面的 cmets 中所说的:
(是的,)我从 列表。每次应用切换到时,这条线都会让我的应用“重置” Safari 和返回。这就是调试器也被分离的原因。
【讨论】:
以上是关于iOS 8 上的 Facebook 登录;登录切换后应用程序无法运行的主要内容,如果未能解决你的问题,请参考以下文章
切换到 Safari 进行 Facebook 登录会终止 iOS 应用程序