0

升级到 Xcode 11.3.1 后,我们注意到我们的应用在打开时开始在某些设备上崩溃。它发生在不同的 iOS 版本和 iPhone 型号上。但是,在某些具有相同 iOS 版本或 iPhone 型号的设备上,该应用程序运行良好。

在这些设备上安装早期版本的应用程序(使用早期 Xcode 版本构建)时不会发生崩溃。

Optional在调试时,我们发现在使用登录模块的演示者时尝试解包时会发生崩溃。这个演示者在创建和分配时有一个值,但是在rootViewControllerAppDelegatewindow.rootViewController = navigationController中设置我们之后,执行跳转到viewDidLoad()下面显示的函数,此时演示者是nil.

class LoginViewController: LoginPasswordResetViewController {
    var presenter: LoginPresenterProtocol!

    override func viewDidLoad() {
        super.viewDidLoad()

        updateUI(model: presenter.loadViewModel())
        presenter.viewDidLoad()
    }
}

AppDelegate.swift 中的相关代码:

class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?

func application(_: UIApplication, didFinishLaunchingWithOptions _: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {

    let env = Environment()

    if let app = UIApplication.shared.delegate as? AppDelegate,
        let window = app.window,
        let loginVC = LoginModule().createModule(moduleData: LoginModuleData(env: env),
                                                 service: LoginService(env: env),
                                                 storageService: LocalStorageService(env: env)) {

        let navigationController = UINavigationController(rootViewController: loginVC)

        window.rootViewController = navigationController
        window.makeKeyAndVisible()
    }
    return true
}

我尝试使用此处提到的 SceneDelegate.swift Set RootViewController iOS 13来设置 RootViewController 没有运气。

关于什么可能是这个问题的原因的任何想法?

附加信息:

createModule函数初始化并设置presenter

func createModule(moduleData: LoginModuleDataProtocol, service: LoginServiceProtocol, storageService: LocalStorageServiceProtocol) -> LoginViewController? {
    guard let viewController: LoginViewController = UIStoryboard.viewController(from: self) else {
        return nil
    }
    let presenter = LoginPresenter()
    let interactor = LoginInteractor()
    let router = LoginRouter()

    // VC
    viewController.presenter = presenter
    // Presenter
    presenter.viewController = viewController
    presenter.interactor = interactor
    presenter.router = router
    // Interactor
    interactor.presenter = presenter
    interactor.dataManager = LoginDataManager(data: moduleData, service: service, storageService: storageService)
    // Router
    router.viewController = viewController

    return viewController
}

创建模块后,loginVC变量具有presenter应有的值,但只要我们window.rootViewController = navigationControllerpresenteris赋值nil

4

1 回答 1

0

我设法使它工作。我不得不使用SceneDelegate加载组件来启动我的 iOS 13 应用程序,同时仍然支持 iOS 12 ,但我只有在阅读了如何正确配置它之后才设法让它工作。

所以这是对我有用的结果:

SceneDelegate.swift:

import UIKit
@available(iOS 13.0, *)
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
    var window: UIWindow?

    func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
        let env = Environment()

        if let windowScene = scene as? UIWindowScene,
            let loginVC = LoginModule().createModule(moduleData: LoginModuleData(env: env),
                                                     service: LoginService(env: env),
                                                     storageService: LocalStorageService(env: env)) {
            self.window = UIWindow(windowScene: windowScene)
            self.window!.rootViewController = UINavigationController(rootViewController: loginVC)
            self.window!.makeKeyAndVisible()
        }
    }
}

AppDelegate.swift:

import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
    var window: UIWindow?

    func application(_: UIApplication, didFinishLaunchingWithOptions _: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        if #available(iOS 13.0, *) {} else {
            let env = Environment()

            if let app = UIApplication.shared.delegate as? AppDelegate,
                let window = app.window,
                let loginVC = LoginModule().createModule(moduleData: LoginModuleData(env: env),
                                                         service: LoginService(env: env),
                                                         storageService: LocalStorageService(env: env)) {
                window.rootViewController = UINavigationController(rootViewController: loginVC)
                window.makeKeyAndVisible()
            }
        }
        return true
    }
于 2020-02-25T08:46:56.680 回答