Reputation: 650
I want to navigate to a specific view controller after I pressed the push notification, how to do it in here with OneSignal Push notifications?
_ = OneSignal(launchOptions: launchOptions, appId: "b2f7f966-d8cc-11e4-bed1-df8f05be55ba") { (message, additionalData, isActive) in
NSLog("OneSignal Notification opened:\nMessage: %@", message)
if additionalData != nil {
NSLog("additionalData: %@", additionalData)
// Check for and read any custom values you added to the notification
// This done with the "Additonal Data" section the dashbaord.
// OR setting the 'data' field on our REST API.
if let customKey = additionalData["newid"] as! Int {
//The navigation to a view controller code should be goes here...
//I've no idea how to do it, I've tried some ways from stackoverflow also didn't work for me
}
}
}
Upvotes: 2
Views: 1673
Reputation: 101
You can use a segue like jkasten proposes, or also:
let controller = self.storyboard!.instantiateViewControllerWithIdentifier("storyboardID") as! ClassOfYourView
self.presentViewController(controller, animated: true, completion: nil)
Either way you will still need to create a storyboardID.
Upvotes: 1
Reputation: 3948
There are a few ways to do this, one of them is to call this from your "newid" if statement.
self.performSegueWithIdentifier("GoToViewController", sender:self)
If the code above does not work I recommend trying a few other answers from Opening viewController programatically in swift
Upvotes: 0