0

Whenever the user gets a notification and they click it, they should be taken to that specific tab. For instance, when a user gets a message and they open the notification, the app should open up but to the messages tab. Think of twitter & dm's. With my project, Im trying to implement something very similar. In the appdelegate and notificationReceived (OneSignal for Push notifications), I've attempted to do so by this:

 let sb: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
            let messageNavigationController: UINavigationController = sb.instantiateViewController(withIdentifier: "MessagesNav") as! UINavigationController
            self.window = UIWindow(frame: UIScreen.main.bounds)
            self.window?.rootViewController = messageNavigationController
            self.window?.makeKeyAndVisible()

But nothing happens. Whenever a user receives a notification, the app just opens up one the main tab (tab 0). What am i doing incorrectly?

Vandal
  • 708
  • 1
  • 8
  • 21
  • BTW, if you're using a smartphone, what are you clicking, or clicking with? Do you have a mouse connected to your device? – dbDev Apr 14 '23 at 01:48

1 Answers1

1

I don't know what you mean by notificationReceived, that's not a predefined function of UIApplicationDelegate. If you want to open different pages when a push notification happens with OneSignal you should probably pass your handling function to the handleNotificationAction of OneSignal.initWithLaunchOptions.

Also you mention changing tabs in your tab controller but the code you pasted is setting your root view to a UINavigationController. If you actually want to change tabs you need to get a reference to the tab controller and set the correct selectedIndex on it.

NewShelbyWoo
  • 722
  • 1
  • 7
  • 21
  • Thanks for your answer. I figured it out by moving that over to the handle notification action & the custom tab bar controller class. – Vandal Apr 27 '17 at 23:10