How do I specify a custom icon for a static UIApplicationShortcutItem in my iOS 9 App?

Chris Allwein picture Chris Allwein · Sep 13, 2015 · Viewed 13.8k times · Source

I'm currently implementing home screen Quick Actions for my iOS 9 app using 3D Touch. I have several actions using the existing System icons from the defined UIApplicationShortcutIconType enum.

An Example:

<dict>
    <key>UIApplicationShortcutItemIconType</key>
    <string>UIApplicationShortcutIconTypeSearch</string>
    <key>UIApplicationShortcutItemTitle</key>
    <string>Search for Parking</string>
    <key>UIApplicationShortcutItemType</key>
    <string>SEARCH</string>
</dict>

However, for one of the actions I want to use a custom icon. I have tried replacing the UIApplicationShortcutItemIconType string with the name of my image asset, but that doesn't work.

It's easy enough to do for dynamic actions using UIApplicationShortcutIcon.iconWithTemplateImageName(), but this action needs to be static.

Answer

Chris Allwein picture Chris Allwein · Sep 13, 2015

Instead of using the UIApplicationShortcutItemIconType key, replace it with the UIApplicationShortcutItemIconFile key and then supply the name of your image file or ImageAsset.

Like this:

<dict>
    <key>UIApplicationShortcutItemIconFile</key>
    <string>MyCustomImageName</string>
</dict>

The rest of the keys can stay as they were.