Ios 实现UIApplicationShortcutItem

Ios 实现UIApplicationShortcutItem,ios,uikit,3dtouch,uiapplicationshortcutitem,Ios,Uikit,3dtouch,Uiapplicationshortcutitem,我在查看UIKitframework参考资料时遇到了一个问题。它是用于3D触摸的 它包含以下代码示例: let existingShortcutItems = UIApplication.sharedApplication().shortcutItems ?? [] let anExistingShortcutItem = existingShortcutItems[anIndex] var updatedShortcutItems = existingShortcutItems let aMu

我在查看
UIKit
framework参考资料时遇到了一个问题。它是用于3D触摸的

它包含以下代码示例:

let existingShortcutItems = UIApplication.sharedApplication().shortcutItems ?? []
let anExistingShortcutItem = existingShortcutItems[anIndex]
var updatedShortcutItems = existingShortcutItems
let aMutableShortcutItem = anExistingShortcutItem.mutableCopy() as! UIMutableApplicationShortcutItem
aMutableShortcutItem.localizedTitle = “New Title"
updatedShortcutItems[anIndex] = aMutableShortcutItem
UIApplication.sharedApplication().shortcutItems = updatedShortcutItemsode here
如果我是对的,你把它放在应用程序代理中


这是怎么回事?是否调用
localizedTitle
方法来检查所选操作的标题,然后调用具有该标题的操作?操作在哪里?

您提供的代码将允许您创建快捷方式项目(即当用户3D触摸应用程序图标时,与主屏幕上显示的快捷方式相关联的UI)。要响应这些快捷方式项,您需要实现:

- (void)application:(UIApplication *)application
performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem
  completionHandler:(void (^)(BOOL succeeded))completionHandler

在您的UIApplicationLegate中。你可以在报纸上看到。但要点是,当您的应用程序从快捷方式启动时,将调用此方法,您可以检查shortcutItem以执行适当的操作

optional func application( application: UIApplication,
performActionForShortcutItem shortcutItem: UIApplicationShortcutItem,
           completionHandler completionHandler: (Bool) -> Void)