I applied Push Notification in my application.
When my application is in the foreground, my application is working fine.
But when the application is in the background or killed, mine didReceiveRemoteNotificationcalls twice.
I made a general method for handling push notifications and calling this method from didFinishLaunchingWithOptionsanddidReceiveRemoteNotification
Here is my implementation:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
NSDictionary *pushDictionary = [launchOptions valueForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
if (pushDictionary) {
[self customPushHandler:pushDictionary];
}
return YES;
}
AND:
- (void)application:(UIApplication *)application
didReceiveRemoteNotification:(NSDictionary *)userInfo
fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))handler {
[self customPushHandler:userInfo];
}
AND
- (void) customPushHandler:(NSDictionary *)notification {
NSLog(@"Push Notification");
}
When my application is running, the ViewController is pressed once. And when I open my application From the notification banner, then my screen is double-clicked.
I placed NSLog in customPushHandlerand I got it once when the application is in the foreground and twice when I launch it from the notification banner.
What is the problem in my code.?