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      

BUILD THE ULTIMATE PORTFOLIO APP Most Swift tutorials help you solve one specific problem, but in my Ultimate Portfolio App series I show you how to get all the best practices into a single app: architecture, testing, performance, accessibility, localization, project organization, and so much more, all while building a SwiftUI app that works on iOS, macOS and watchOS.

Get it on Hacking with Swift+

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.