On iPhone/iPad after installing the app, app is able to receive notification first time. Once app is inactive, then it stops getting notification in both foreground and background.
Can someone point, what I am I missing . Looks like no issue with message format since I get first time.
Server Code:
message.put("priority", "high");
message.put("content_available",true);
if (to != null)
{
message.put("to", to.replace("\\", ""));
}
if (messageId != null)
{
message.put("message_id", messageId);
}
JSONObject subobj = new JSONObject();
subobj.put("sound", "default");
message.put("notification", subobj);
message.put("data", payload);
if (timeToLive != null)
{
message.put("time_to_live", timeToLive);
}
if (delayWhileIdle != null && delayWhileIdle)
{
message.put("delay_while_idle", true);
}
if (collapseKey != null)
{
message.put("collapse_key", collapseKey);
}
message.put("delivery_receipt_requested", true);
Client Code:
- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions
{
// First run Delete keychain
if (![[NSUserDefaults standardUserDefaults] objectForKey:@"FirstRun"]) {
// Delete values from keychain here
application.applicationIconBadgeNumber = 0;
[self resetKeychain];
[[NSUserDefaults standardUserDefaults] setValue:@"1strun" forKey:@"FirstRun"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
self.viewController = [[MainViewController alloc] init];
CGRect screenBounds = [[UIScreen mainScreen] bounds];
#if __has_feature(objc_arc)
self.window = [[UIWindow alloc] initWithFrame:screenBounds];
#else
self.window = [[[UIWindow alloc] initWithFrame:screenBounds]
autorelease];
#endif
self.window.autoresizesSubviews = YES;
//notification
[self updateDurationLabel];
UIFont *font = [UIFont boldSystemFontOfSize:10.0f];
NSDictionary *attributes = [NSDictionary dictionaryWithObject:font forKey:NSFontAttributeName];
[self.segFromStyle setTitleTextAttributes:attributes forState:UIControlStateNormal];
[self.segToStyle setTitleTextAttributes:attributes forState:UIControlStateNormal];
[self flowManager];
UILocalNotification *remoteNotification = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
if (remoteNotification) {
application.applicationIconBadgeNumber = 0;
self.launchNotification = remoteNotification.userInfo;
NSLog(@"NotificationCheck: remoteNotification");
}
UILocalNotification *localNotification = [launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];
if (localNotification) {
application.applicationIconBadgeNumber = 0;
NSLog(@"NotificationCheck: localNotification");
self.launchNotification = localNotification.userInfo;
NSData* jsonData = [NSJSONSerialization dataWithJSONObject:localNotification.userInfo options:0 error:nil];
NSString* jsonString = [[NSString alloc] initWithBytes:[jsonData bytes] length:[jsonData length] encoding:NSUTF8StringEncoding];
NSLog(@"Dict:%@", jsonString);
}
[self.window makeKeyAndVisible];
return YES;
}