ios - iOS Swift Firebase在应用程序启动时检查用户不起作用
问题描述
我用firebase开发了一个应用程序。应用程序会检查是否有用户在每次启动时登录到 sceneDelegate.swift 文件中。但它仅适用于 iOS 13 设备。iOS 12 设备用户每次都必须登录。我该如何解决这个问题?谢谢。
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
var window: UIWindow?
@available(iOS 13.0, *)
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
// Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.
// If using a storyboard, the `window` property will automatically be initialized and attached to the scene.
// This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead).
let currentUser = Auth.auth().currentUser
if currentUser != nil {
let board = UIStoryboard(name: "Main", bundle: nil)
let navigationController = board.instantiateViewController(identifier: "navigationController") as! UINavigationController
window?.rootViewController = navigationController
}
guard let _ = (scene as? UIWindowScene) else { return }
}
解决方案
AppDelegate
SceneDelegate 是在 iOS 13 中引入的。对于 iOS 12 及更低版本,您应该在'方法中实现相同的逻辑,didFinishLaunchingWithOptions
如下所示:
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
window = UIWindow()
window?.makeKeyAndVisible()
let currentUser = Auth.auth().currentUser
if currentUser != nil {
let board = UIStoryboard(name: "Main", bundle: nil)
let navigationController = board.instantiateViewController(withIdentifier: "navigationController") as! UINavigationController
window?.rootViewController = navigationController
}
return true
}
}
推荐阅读
- material-ui - Material UI 禁用默认的 jss 类
- reactjs - 使用“npm start”运行 React 项目时出错
- sdk - 如何格式化 Visual Studio 扩展的选项(Visual Studio2019)
- javascript - 尝试导入错误:“GridActionsCellItem”未从“@mui/x-data-grid”导出
- python - 如何在 keras 功能 api 上指定 GRU 模型的输入形状?
- android - android studio上的颤振设置
- r - 为什么 ifelse 返回 NA 为假?
- javascript - 拦截箭头键并发送 Enter 代替
- npm - 私有存储库 GitLab 的版本控制
- php - 如何让我的 apache 网站只接受带有特定条目的主机头