Reputation: 2302
I have an application with ability to receive Push Notifications.
When the application is in background mode push notification shows well, but if the application is in foreground mode I want to show my custom view
with information from userInfo
.
How can I notify any viewController
from my appDelegate didReceiveRemoteNotification
to show this custom view and send userInfo
dictionary there?
Can someone help me with my problem?
Upvotes: 2
Views: 264
Reputation: 2935
You can use NSNotificationCenter to notify your viewcotroller from the didReceiveRemoteNotification
. Then you can show custom view as you want with the userinfo dictionary passed in that NSNotificationCenter method .
Upvotes: 1
Reputation: 7373
You could send out a notification and then the viewControllers that you want to be alerted can have observers for them:
NSNotificationCenter.defaultCenter().postNotificationName("nameOfNotification", object: yourVariableContainingUserInfo)
Can you add observers like so:
NSNotificationCenter.defaultCenter().addObserver(self, selector: "nameOfNotification:", name: "nameOfNotification", object: nil)
And your selector would look something like this:
func nameOfNotification(notification: NSNotification) {
if let dict = notification.object as? NSDictionary {
//user your userInfo dictionary here
}
}
Upvotes: 4