Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I access remote push notification data on applicationDidBecomeActive?

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?

like image 527
Man of One Way Avatar asked Jul 18 '11 11:07

Man of One Way


People also ask

How do I see a push 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.

What is remote push notification?

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.

What are remote notifications in Android?

Remote Notifications are notifications sent to a mobile device using a data-channel from a service provider in real-time.


2 Answers

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.

like image 154
Morten Fast Avatar answered Sep 23 '22 11:09

Morten Fast


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> {
    }
}
like image 27
Harry Ng Avatar answered Sep 22 '22 11:09

Harry Ng