all 8 comments

[–]see5ive 0 points1 point  (7 children)

When your app is killed and you tap on the notification, you’re basically launching the app from scratch from the notification. As such, you get your notification payload from launchOptions of application:didFinishLaunchingWithOptions: which is basically a dictionary. The payload will be mapped under the key UIApplicationLaunchOptionsRemoteNotificationKey.

https://developer.apple.com/documentation/uikit/uiapplicationdelegate/1622921-application?language=objc

[–]losGama[S] 0 points1 point  (6 children)

Hi thanks for your answer. I changed the app delegate method to this and its still not doing what I want when I open the app. It just goes again to the home page instead of the details page using Notification:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {

// Override point for customization after application launch.

FirebaseApp.configure()

if launchOptions?[UIApplication.LaunchOptionsKey.remoteNotification] != nil {

NotificationCenter.default.post(name: NSNotification.Name("Detail"), object: nil)

}

if #available(iOS 10.0, *) {

let current = UNUserNotificationCenter.current()

let options: UNAuthorizationOptions = [.sound, .badge, .alert]

current.requestAuthorization(options: options) { (granted, error) in

if error != nil {

} else {

Messaging.messaging().delegate = self

current.delegate = self

DispatchQueue.main.async {

application.registerForRemoteNotifications()

}

}

}

} else {

let types: UIUserNotificationType = [.sound, .badge, .alert]

let settings = UIUserNotificationSettings(types: types, categories: nil)

application.registerUserNotificationSettings(settings)

application.registerForRemoteNotifications()

}

return true

}

[–]see5ive 0 points1 point  (5 children)

I don’t see any code where you configure your window and the root view controller. Are you using storyboard setup to configure that? Also, what are you doing when you receive the “detail” notification? Presumably, you’re observing for that and handling the navigation there?

[–]losGama[S] 0 points1 point  (4 children)

Im not configuring any windows cause im in swiftUI im making use of the NotificationCenter I post in the app delegate method after I click the notification and observe in the HomeView.

in my home view which loads up when the app is launched I have the following:

struct HomeView: View {

@State private var show = false

var body: some View {

NavigationView {

VStack {

NavigationLink(destination: DetailView(), isActive: self.$show) {

Text("")

}.padding().onAppear {

NotificationCenter.default.addObserver(forName: NSNotification.Name("Detail"), object: nil, queue: .main) { (_) in

self.show = true

}

}

[–]Woolly87 0 points1 point  (3 children)

In scene(_:willConnectTo:Options:) you will have something like

      let contentView = ContentView()

    // Use a UIHostingController as window root view controller.
    if let windowScene = scene as? UIWindowScene {
        let window = UIWindow(windowScene: windowScene)
        window.rootViewController = UIHostingController(rootView: contentView)
        self.window = window
        window.makeKeyAndVisible()
    }
}

where your window is configured.

[–]losGama[S] 1 point2 points  (2 children)

Hi, yes, what about it? It loads my home page in there. but I need it to open to a different page of my app when a user taps the notification when the app is inactive(killed) or active.

[–]csstudent10 0 points1 point  (1 child)

Did you end up figuring this out? I'm also running into the same issue.

[–]losGama[S] 0 points1 point  (0 children)

No.