Use UIApplicationShortcutItemIconFile as a key and the name of your image file (with or without file extension) as the string. For example: using an image named "lightning.png" you would add the following to Info.plist...
<key>UIApplicationShortcutItems</key>
<array>
<dict>
<key>UIApplicationShortcutItemIconFile</key>
<string>lightning</string>
<key>UIApplicationShortcutItemTitle</key>
<string>Search for Parking</string>
<key>UIApplicationShortcutItemType</key>
<string>SEARCH</string>
</dict>
</array>
The image can be stored either in your project tree or in Assets.xcassets. If you store the image in Assets.xcassets, use the Image Set name if you name the set something different from your file name.
Your image file needs to be a PNG (if you want transparency), square, single color, and 35x35 pixels. Multi-color images essentially get a black overlay.
Here's a test image that meets the above criteria:
Just save this image as "lightning.png", drag it into your project tree, and use the code above in your Info.plist file.
For those not comfortable editing the Info.plist as source code, here's how the above should look if you do it natively in the Property List:
To attach these shortcuts to code, you do so in the AppDelegate.swift. Add the following:
func application(application: UIApplication, performActionForShortcutItem shortcutItem: UIApplicationShortcutItem, completionHandler: (Bool) -> Void) {
if shortcutItem.type == "SEARCH" {
print("Shortcut item tapped: SEARCH")
// go to SEARCH view controller
}
}
It's worth noting that the convention for UIApplicationShortcutItemType is not all caps (e.g. "SEARCH"), but rather using your bundle identifier as a pre-fix:
com.myapps.shortcut-demo.search
<string>
are you using? – Elevon