CraigH
CraigH

Reputation: 2061

Swift: How to make Push Notification open to specific tab on tab bar controller

I have an iOS 8 app written using swift. My app has a tab bar controller with 4 tabs , one of which is the "Notifications" tab.

I am using Parse to send push notifications. When the user opens a push notification from the Home/Lock screen I want it to open to the "Notifications" tab

I haven't been able to find any tutorials or questions in swift to help here. Can someone explain how to accomplish this?

I have this in my AppDelegate but It didnt work:

func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) {

PFPush.handlePush(userInfo)
let tab :CustomTabBarController = self.window?.rootViewController as CustomTabBarController
tab.selectedIndex = 2
}

Upvotes: 1

Views: 3630

Answers (1)

The Kraken
The Kraken

Reputation: 3158

Changing the selected index doesn't automatically change the displayed view controller. Use the selectedViewController: method instead. This will update the selected index on the tab bar as well. See Apple Docs.

Example:

tab.selectedViewController = tab.viewControllers[1]

Upvotes: 6

Related Questions