0

I'm reading about adding dynamic shortcuts to the homescreen for 3dTouch enabled devices. It essentially boils down to reading / writing to the shortcutItems member array of UIApplication.sharedApplication.

My question is: is this array persisted? If I close or remove the app - will the configuration of the shortcuts be kept?

In other words - how often should I set the desired shortcuts for my app? Once? On every launch? On every transition to the background?

Roay Spol
  • 1,188
  • 1
  • 11
  • 17

1 Answers1

2

It's persistent while your app is installed on device. You update it when you need to. If you have static shortcuts you can benefit from having them available right after your app is being installed on device, just include them in your Info.plist under UIApplicationShortcutItems.

pronebird
  • 12,068
  • 5
  • 54
  • 82
  • Thanks! Yes, static ones are cool, but I need to add some dynamic stuff. So I should execute it where? if in some kind of app initialization method, then I need to check if the items are already there - how would I do there? compare some tags? Also, is everything in the UIApplication persisted while the app is installed? – Roay Spol Jul 08 '16 at 14:21
  • You can update shortcuts at any time of the lifecycle of your application. You can do that in application delegate once your app finished loading and you can do that when certain condition met. It's up to you how you check and maintain them. You assign unique identifier to each shortcut and use it to reference different kinds of shortcuts that your app supports and also use the same identifiers to run the corresponding action when user taps on shortcut from home screen. All of that is pretty much outlined in documentation. – pronebird Jul 08 '16 at 14:53
  • Apart from that there is nothing wrong in replacing all of shortcuts at once when you need to re-create the home screen menu. So you don't really have to do any complex management. Just create an array of new shortcuts and set them on UIApplication. – pronebird Jul 08 '16 at 14:58
  • As of persistence of UIApplication, there are couple of things that are saved by system and available on each run. From the top of my head: shortcuts and notification categories. If you need to persist any of your application data then consider using NSUserDefaults for settings, keychain for passwords, CoreData for general purposes. – pronebird Jul 08 '16 at 15:08