UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

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.

3      

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

3      

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.

3      

TAKE YOUR SKILLS TO THE NEXT LEVEL If you like Hacking with Swift, you'll love Hacking with Swift+ – it's my premium service where you can learn advanced Swift and SwiftUI, functional programming, algorithms, and more. Plus it comes with stacks of benefits, including monthly live streams, downloadable projects, a 20% discount on all books, and free gifts!

Find out 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.