When receiving a remote push notification as the application is in the background, the app enters applicationDidBecomeActive. From there, how can I access the NSDictionary of data from the notification?
Turn on notifications for Android devicesTap More on the bottom navigation bar and select Settings. Tap Turn on notifications. Tap Notifications. Tap Show notifications.
Overview. Use remote notifications (also known as push notifications) to push small amounts of data to devices that use your app, even when your app isn't running. Apps use notifications to provide important information to users. For example, a messaging service sends remote notifications when new messages arrive.
Remote Notifications are notifications sent to a mobile device using a data-channel from a service provider in real-time.
The notification data is delivered to your app in application:didReceiveRemoteNotification:
. If you want to process it in applicationDidBecomeActive:
you should store it in application:didReceiveRemoteNotification:
and read it again in applicationDidBecomeActive
.
Swift version:
var dUserInfo: [NSObject : AnyObject]?
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// code...
if let info = launchOptions?[UIApplicationLaunchOptionsRemoteNotificationKey] as? [NSObject : AnyObject] {
dUserInfo = info
}
return true
}
func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) {
dUserInfo = userInfo
}
func applicationDidBecomeActive(application: UIApplication) {
// code...
self.yourAction(dUserInfo)
}
func yourAction(userInfo: [NSObject : AnyObject]?) {
if let info = userInfo?["aps"] as? Dictionary<String, AnyObject> {
}
}
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