1

How do I handle this method in new SwiftUI app lifecycle? I am looking at the Scene but it does not have any info about SceneDelegate methods

func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) { method in SwiftUI new App cycle.

2
  • There is no SceneDelegate in SwiftUI life cycle. Why do you need it? What do you want to do? Commented Aug 31, 2020 at 7:15
  • For the remote notification. I am handing the remote notification in this method when the app is not running and is launched from the notification. Commented Aug 31, 2020 at 7:33

2 Answers 2

3

You can get notified when a device receives a specific notification using .onReceive modifier. for your case, you can use .onReceive like this on top of one of your view(s) to get notified for scene connections:

.onReceive(NotificationCenter.default.publisher(for: UIScene.willConnectNotification)) { notification in } 
Sign up to request clarification or add additional context in comments.

Comments

0

You can get notification through userNotificationCenter even when the app is not running and is launched from the notification.

func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) { print("open notification") let userInfo = response.notification.request.content.userInfo print(userInfo) completionHandler() } 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.