我在使用 3D Touch 动态快速操作快捷方式时遇到了一个非常简单的问题。
我希望在应用程序终止时清除快捷方式(通过双击主页按钮并向上滑动)。
我调用 UIApplication.sharedApplication().shortcutItems.removeAll()
如下:
func applicationWillTerminate(application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
// Saves changes in the application's managed object context before the application terminates.
UIApplication .sharedApplication().shortcutItems?.removeAll()
self.saveContext()
}
但没有任何效果,使用 3D touch 时仍然显示快速操作。
如果我将 UIApplication.sharedApplication().shortcutItems?.removeAll()
放在里面
func applicationDidEnterBackground(application: UIApplication)
,这完全符合预期……
我阅读了一些关于 applicationDidEnterBackground
的内容,这是由于后台处理或其他原因在大多数情况下使用的功能......但是当用户使用终止应用程序时,必须有一种方法来实现我想要的向上滑动应用程序监视器。
谢谢
最佳答案
没试过。但是这个调整应该有效。 在 applicationWillTerminate 上启动后台任务,并在一些小的延迟后结束它。同时,您可以调用“UIApplication .sharedApplication().shortcutItems?.removeAll()”。 这有望清除快捷方式项目。
关于Swift:在应用程序退出时清除 .sharedApplication().shortcutItems,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34790495/