BLACK FRIDAY SALE: Save 50% on all my Swift books and bundles! >>

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.

1      

@emin  

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"?

1      

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.

1      

Hacking with Swift is sponsored by Guardsquare

SPONSORED AppSweep by Guardsquare helps developers automate the mobile app security testing process with fast, free scans. By using AppSweep’s actionable recommendations, developers can improve the security posture of their apps in accordance with security standards like OWASP.

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.