在iPhone X上停用时触发applicationDidBecomeActive [英] applicationDidBecomeActive firing on deactivation on iPhone X
问题描述
是否有其他人遇到applicationDidBecomeActive
在新iPhone X上应用程序的停用时错误地触发?
Is anyone else having trouble with applicationDidBecomeActive
incorrectly firing on deactivation of the app on the new iPhone X?
这是我的测试应用程序:
Here's my test app:
class ViewController: UIViewController {
required init?(coder aDecoder: NSCoder) {
super.init(coder:aDecoder)
NotificationCenter.default.addObserver(
self,
selector: #selector(fired),
name: .UIApplicationDidBecomeActive,
object: nil
)
}
@objc func fired(_:Any) {
print("fired")
}
}
在iPhone X模拟器上运行该应用程序.自然,我在控制台中看到被解雇".到目前为止,一切都很好.现在从侧面或向上滑动主页指示器,以切换到其他应用程序或调出应用程序切换器.我看到解雇"再次出现在控制台中!
Run the app on the iPhone X simulator. Naturally, I see "fired" in the console. So far, so good. Now swipe the home indicator sideways or up, to switch to a different app or to bring up the app switcher. I see "fired" appear again in the console!
这似乎是错误的,并且将我所有的应用都丢进了混乱之中.我该如何应对停用时收到激活通知?
This seems just wrong, and is throwing all of my apps into a kerfuffle. How can I cope with getting an activation notification on deactivation?
推荐答案
实际上,当在iPhone X Simulator中停用该应用程序时,会迅速连续触发三个通知:
In fact there are three notifications fired in rapid succession when the application is deactivated in the iPhone X Simulator:
- UIApplicationWillResignActive
- UIApplicationDidBecomeActive
- UIApplicationWillResignActive
这是错误的(您可能要提交错误报告),但是如果用户使用,这是可能发生的事情 停用-激活-快速停用应用程序,因此该应用程序 无论如何应该应对这种情况.
This is wrong (and you might want to file a bug report), but it is something that could happen if a user deactivates - activates – deactivates the app quickly, so the app should cope with that situation anyway.
两个通知都必须以对称的方式进行处理(即使存在该错误,它们也要保持适当的平衡):完成的操作 在激活"状态下,必须反转为停用"状态.
Both notifications must be handled in a symmetric fashion (and they come properly balanced, even with that bug): Actions done on "activate" must be reversed on "deactivate".
这篇关于在iPhone X上停用时触发applicationDidBecomeActive的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!