Reputation: 827
I am using parse push notification service.
If my app is running , I get the data from my notification in the following delegate function.
func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) {
PFPush.handlePush(userInfo)
println(userInfo)
if application.applicationState == UIApplicationState.Inactive {
}
}
But in case if my app is not running, and notification generates, then I dont, konw which function is used to generate that notification and get data from that notification.
Upvotes: 0
Views: 4284
Reputation: 3513
If your app is not running (background or foreground) then the only way to get the notification payload data is when the user opens your app by tapping on the notification. If that happens you can use the didFinishLaunchingWithOptions
method to retrieve the data. Other than that, the best way to store the payload data is to store it in your server side database as you send out the notification. Then you can always make a request to retrieve the notifications. This will also give you mechanism to manage badge counts.
Upvotes: 2
Reputation: 1429
Not sure about Swift or Parse, but if you are using Objective-C, the notification is passed to non-running app via:
- (BOOL)application:(UIApplication *)app didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSDictionary *remoteNotify = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
}
That's assuming the user opened your notification.
Upvotes: 0
Reputation: 22343
You could save your notifications into the NSUserDefaults
and check, after your app is active again, if any new data is stored inside your NSUserDefaults
. I would create an array of userInfo-objects and add new entries in your array.
After your app is active again, you could clear the array with the unseen notifications.
let defaults = NSUserDefaults.standardUserDefaults()
var unseenNotifications:[[NSObject: AnyObject]] = []
//Set
defaults.setValue(unseenNotifications, forKey: "unseen")
//Get
unseenNotifications = defaults.valueForKey("unseen") as! [[NSObject : AnyObject]]
Upvotes: 0