Skip to content

Instantly share code, notes, and snippets.

@ycui1
Last active January 5, 2020 14:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ycui1/f3fc47059582bc2395bd69c752360f7a to your computer and use it in GitHub Desktop.
Save ycui1/f3fc47059582bc2395bd69c752360f7a to your computer and use it in GitHub Desktop.
func sceneWillResignActive(_ scene: UIScene) {
var shortcutItems = UIApplication.shared.shortcutItems ?? []
if shortcutItems.isEmpty {
shortcutItems += [
UIApplicationShortcutItem(type: "Test Type 0", localizedTitle: "Test Title 0"),
UIApplicationShortcutItem(type: "Test Type 1", localizedTitle: "Test Title 1")
]
} else {
if let mutableShortcutItem = shortcutItems.first?.mutableCopy() as? UIMutableApplicationShortcutItem {
mutableShortcutItem.type = "Updated Type 0"
mutableShortcutItem.localizedTitle = "Updated Title 0"
mutableShortcutItem.icon = UIApplicationShortcutIcon(type: UIApplicationShortcutIcon.IconType.love)
shortcutItems[0] = mutableShortcutItem
}
}
UIApplication.shared.shortcutItems = shortcutItems
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment