在我的支持iOS 11到iOS 13的应用中,我遇到了一个大问题。我的大多数appDelegate方法都不再被调用(例如didFinishLaunchingWithOptions
:applicationDidEnterBackground
或applicationDidBecomeActive
除外)。但是,我读了this post,但我既不支持iPad,也不支持多个窗口,我没有/使用SceneDelegate,并且我的info.plist文件中也没有任何“应用程序场景清单”。还有其他要做的事情来检索AppDelegate的正常行为吗?谢谢!
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
// Still called, app launches UI normally.
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
self.window = UIWindow(frame: UIScreen.main.bounds)
self.window?.rootViewController = LoadingViewController.instantiate()
self.window?.makeKeyAndVisible()
return true
}
// Not called anymore
func applicationWillResignActive(_ application: UIApplication) {
log.verbose("applicationWillResignActive")
}
// Not called anymore
func applicationDidEnterBackground(_ application: UIApplication) {
log.verbose("applicationDidEnterBackground")
RideController.shared.prepareForBackground()
}
// Not called anymore
func applicationWillEnterForeground(_ application: UIApplication) {
log.verbose("applicationWillEnterForeground")
}
// Not called anymore
func applicationDidBecomeActive(_ application: UIApplication) {
log.verbose("applicationDidBecomeActive")
RideController.shared.prepareForForeground() // Not called anymore
// Watch
WatchController.shared.startSession()
}
func applicationWillTerminate(_ application: UIApplication) {
log.verbose("applicationWillTerminate")
RideController.shared.prepareForBackground()
}
}
哇!我发现了错误。我在应用程序中使用Pod Firebase,并且显然Firebase Cloud Messaging服务(FCM)在启动时使应用程序委托蒙上了阴影。我必须在我的info.plist文件中将此键FirebaseAppDelegateProxyEnabled
设置为NO才能对其进行修复。