Swift:在应用程序退出时清除 .sharedApplication().shortcutItems

标签 swift 3dtouch

我在使用 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/

相关文章:

swift - 提交应用程序可接受的快速版本是什么?

ios - 自定义 3D touch 和 WkWebView 问题

ios - 如果方向改变,如何设置框架?

swift - 快速检查 NSError 代码

ios - 在 App Delegate 中调用 IBAction

ios - 禁用 iOS 10 快速操作小部件

ios - didFinishLaunching 中的 UIApplicationShortcutItem

swift - 3D Touch 和 UITableViewCell

ios - 快速组合 : `append` which does not require output to be equal?

ios - 在应用程序委托(delegate)的 didRegisterForRemoteNotificationsWithDeviceToken 上调用时,IBOutlet 似乎为零