【问题标题】:ViewWillDisappear IS called on force close in IOS 10.3 but not IOS 11ViewWillDisappear 在 IOS 10.3 中被调用强制关闭,但在 IOS 11 中没有
【发布时间】:2018-05-09 14:59:38
【问题描述】:

我使用 ViewWillDisappear 来确定用户是否离开了特定屏幕并设置了标志。

但是,如果应用强制关闭,我不希望我的代码被调用。

问题在于,当强制关闭时,似乎在 IOS 10.3.1 和 10.3.3 中调用了 ViewWillDisappear(仅在不在模拟器上的设备上)

但是,在 IOS 11 中,它被调用。

这是一个已知问题吗?

我是否可以使用其他方法来确定用户在没有强制关闭屏幕的情况下离开了屏幕?

【问题讨论】:

    标签: ios iphone swift


    【解决方案1】:

    这对我有帮助:

    override func viewWillDisappear(_ animated: Bool)
    {
        super.viewWillDisappear(animated)
    
        if UIApplication.shared.applicationState == .active
        {
            // app wasn't closed, it's just a common situation when user left the screen
        }
    }
    

    即使应用程序在后台(即异步操作完成)时应该离开屏幕,它也可以工作,因为 viewWillDisappear 会延迟并在应用程序激活时调用。

    【讨论】:

      猜你喜欢
      • 2012-07-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-05-28
      • 2021-05-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多