TEAM LICENSES: Save money and learn new skills through a Hacking with Swift+ team license >>

How to best handle launch options (like shortcut item, push notification or spotlight)?

Forums > iOS

I am once again implementing shortcuts (UIApplicationShortcutItem) and I cannot think of elegant way how to react when user launches the app via particular shortcut. Say you want to navigate to specific section in the app or to do something else. When the app is already running and shortcut is activated then it is just a matter of NotificationCenter but when launching, the observers are not yet set up.

This same applies to push notifications and SpotLight items when the app is launching and not already running.

Best way so far I found is to just store closure which handles the item and then fire it after the initial screen has loaded but I think there has to be better solution.



Still haven't worked with shortcuts but i am really interested how this can work :) If you are using a Coordinator it helps but it seems you need something a bit more low lever...can you even add an observer in "willBecomeActive"?


Yea coordinator would probably help but I dont have it setup yet. Looks like I am going to just wrap the NotificationCenter call in closure and call it once the main controller loads.


Hacking with Swift is sponsored by Superwall.

SPONSORED Superwall lets you build & test paywalls without shipping updates. Run experiments, offer sales, segment users, update locked features and more at the click of button. Best part? It's FREE for up to 250 conversions / mo and the Superwall team builds out 100% custom paywalls – free of charge.

Learn More

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

Unknown user

You are not logged in

Log in or create account

Link copied to your pasteboard.