I'm seeing a peculiar behavior with my push notification and was wondering if anyone has any advise on what I did wrong or should do.
I have my application:(UIApplication*)application didReceiveRemoteNotification:
written as follows:
- (void)application:(UIApplication*)application didReceiveRemoteNotification: (NSDictionary*)userInfo
{
NSLog(@"Received notification: %@", userInfo);
[self addMessageFromRemoteNotification:userInfo updateUI:YES];
}
As you can see, I'm not worried about the state of the app. I just want to log a message whenever I get a PN.
My setup is as per the documentation from Apple and I can receive push notifications.
The following are the expected behaviours when a PN comes in:
Now, the following is the peculiar behaviour I am seeing:
Has anyone seen this behaviour before? Is this what should happen? I couldn't see anything in the Apple documentation regarding this... Also, would there be a way around this?
If the app was not running in background, but initially launched from the push notification and you have didFinishLaunchingWithOptions: implemented, you need to implement your code there:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions {
if (launchOptions != nil) {
NSDictionary* userInfo = [launchOptions valueForKey:@"UIApplicationLaunchOptionsRemoteNotificationKey"];
if (userInfo != nil) {
NSDictionary* apsInfo = [userInfo objectForKey:@"aps"];
NSString* custom = [userInfo objectForKey:@"yourCustomPushData"];
// do something with it
}
}
//...
}
I have the same behaviour. It drives me nuts but I think that's the way iOS works.
Below an excerpt from the apple documentation. This is regarding the application:didFinishLaunchingWithOptions when the app is not running. It looks like it's the same for when the app is in background/didReceiveRemoteNotification.
"If the action button is tapped (on a device running iOS), the system launches the application and the application calls its delegate’s application:didFinishLaunchingWithOptions: method (if implemented); it passes in the notification payload (for remote notifications) or the local-notification object (for local notifications).
If the application icon is tapped on a device running iOS, the application calls the same method, but furnishes no information about the notification . " From: http://developer.apple.com/library/ios/#documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/IPhoneOSClientImp/IPhoneOSClientImp.html#//apple_ref/doc/uid/TP40008194-CH103-SW1
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