1

I currently have UIApplicationShortcutItem working, however, I would like to use my own custom Icon.

I know that I can use iconWithTemplateImageName to get my own custom icon. However, I would rather not include 100s of icons with the app. It seems that iconWithTemplateImageName requires the image file to be included in the xcassets.

I have a function that downloads and save an image to the Document folder upon the user dynamically adding UIApplicationShortcutItem. Is there a way to referance the newly downloaded image.

How I add UIApplicationShortcutItem

let icon = UIApplicationShortcutIcon(templateImageName: fileName)
let newItem = UIMutableApplicationShortcutItem(type: "Chance", localizedTitle: title, localizedSubtitle: chances.joinWithSeparator(", "), icon:  icon, userInfo: ["Items":chances])
existingShortcutItems.append(newItem)
UIApplication.sharedApplication().shortcutItems = existingShortcutItems

Where fileName is the path to an image I have saved. I have tried both the full path and just the file name. Ofcourse that wont work since its not in the xcassets

Is there a way to add the image to the xcassets at runtime?

Is there a way to use an image on the fly?

Working version of the code:

let icon = UIApplicationShortcutIcon(type: .Favorite)
let newItem = UIMutableApplicationShortcutItem(type: "Chance", localizedTitle: title, localizedSubtitle: chances.joinWithSeparator(", "), icon:  icon, userInfo: ["Items":chances])
existingShortcutItems.append(newItem)
UIApplication.sharedApplication().shortcutItems = existingShortcutItems
Cripto
  • 3,581
  • 7
  • 41
  • 65

0 Answers0