Reputation: 333
I'm new to IOS programming, but I can't seem to make a notification open to a specific screen from my storyboard. The notification appears like I expect it to, but I have no idea to assign a new behavior to tapping it.
Thanks
Edit: Code added
// Local notification of event
var localNotification:UILocalNotification = UILocalNotification()
localNotification.alertAction = "Testing notifications on iOS8"
localNotification.alertBody = "You have recieved a new secure communication!"
localNotification.fireDate = NSDate(timeIntervalSinceNow: delay)
localNotification.soundName = UILocalNotificationDefaultSoundName
localNotification.category = "invite"
UIApplication.sharedApplication().scheduleLocalNotification(localNotification)
This should open to a specific UI View.
Upvotes: 0
Views: 1308
Reputation: 119031
You need to start with code in your app delegate to pick up the local notification when it is received by the app.
Once you have that you need to think about your app and its view controller hierarchy a little, and also consider that the app might just have started (so it will be at your root view controller) or it could have been running for ages (so it could be anywhere in your hierarchy).
Mainly you want to consider here whether you're covering everything, like presenting a modal view and then dismissing, or whether your pushing onto the current stack and allowing the user to pop back to where they were. It's less likely that you want to tear the current hierarchy down and start from scratch with the notification controller but that is also an option.
So, generally you'll get the root view controller for the app delegates window, which will usually be a full screen navigation controller. One you have that you can either present your notification controller (created from the same storyboard as the navigation controller) or push it onto the stack.
Any more complex scheme is built on this footing. Mainly you should try to restrict the knowledge you give to the app delegate so it just knows the storyboard id of the navigation controller. If you need to pass the notification to the controller then it is best to define a protocol just for that which the app delegate uses and the notification controller conforms to.
Upvotes: 1