My app allows remote push notifications to a user. How do I enable it to be opened in a specific view controller when the user taps on the push notification? I want the app to open and navigate to a specific view controller depending on the push notification received.
To do this you need to set an identifier
for each ViewController
that your app may be opened with, and then check the payload
in the launchOptions
argument of application:didFinishLaunchingWithOptions:
in your AppDelegate
Here are the steps to doing this:
In your PFPush
, use setData
to add a key to your payload with the identifier: notification.setData(["alert":"your notification string", "identifier":"firstController"])
Set the identifier
on each ViewController
by selecting it and changing the following values
payload
with the key identifier
if let payload = launchOptions?[UIApplicationLaunchOptionsRemoteNotificationKey] as? NSDictionary, identifier = payload["identifier"] as? String {
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewControllerWithIdentifier(identifier)
window?.rootViewController = vc
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With