簡體   English   中英

實現UIApplicationShortcutItem

[英]Implementing a UIApplicationShortcutItem

我正在查看UIKit框架參考,並遇到了UIApplicationShortcutItem 適用於3D Touch。

它包含以下代碼示例:

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

要么

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

在您的UIApplicationDelegate中。 您可以在《 UIApplicationDelegate協議參考指南》中閱讀有關內容。 但要點是,從快捷方式啟動您的應用程序時,將調用此方法,您可以檢查shortcutItem來執行適當的操作。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM