Note: As of this writing the Simulator does not support 3D Touch.
I defined the icon type (UIApplicationShortcutItemTypeShare) to show the share icon. There are 29 different icons you can choose from as of this writing. Find them here.
(Swift 2.2)
Step 1: Define Shortcut Menu Items
Do this in the Info.plistI defined the icon type (UIApplicationShortcutItemTypeShare) to show the share icon. There are 29 different icons you can choose from as of this writing. Find them here.
Step 2: Handle Action for Shortcut Item
func application(application: UIApplication, performActionForShortcutItem shortcutItem: UIApplicationShortcutItem, completionHandler: (Bool) -> Void) { if let tabVC = self.window?.rootViewController as? UITabBarController { if shortcutItem.type == "Search" { tabVC.selectedIndex = 0 } else if shortcutItem.type == "Add New" { tabVC.selectedIndex = 1 } } }
Want to create a dynamic shortcut?
Maybe you want to show/not show shortcuts or show shortcuts with dynamic info like a count of items.func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { // DYNAMIC SHORTCUT // Download new data to add it in the localizedSubtitle. // Like localizedSubtitle: "You have \(number) new ____" if let shortcutItems = application.shortcutItems where shortcutItems.isEmpty { let dynamicShortcut = UIMutableApplicationShortcutItem(type: "Add New", localizedTitle: "Add New", localizedSubtitle: "Create a new lead", icon: UIApplicationShortcutIcon(templateImageName: "addNewIcon"), userInfo: nil) application.shortcutItems = [dynamicShortcut] } return true }
(Swift 2.2)
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.