I have the following code running to handle a push notification -
I receive the notification -> tap on it -> and then performing a jsCallBack -> passing the custom data as parameters to a JS function.
but this works only when the app is running in background or foreground.
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
//Handle notification when the user click it while app is running in background or foreground.
[[Pushbots sharedInstance] receivedPush:userInfo];
//Get Custom field data
NSString* Value1 = [userInfo objectForKey:@"customval1"];
NSString* Value2 = [userInfo objectForKey:@"customval1"];
NSLog(@"%@", Value1);
NSLog(@"%@", Value2);
NSString * jsCallBack = [NSString stringWithFormat:@"testfromdelegate('%@','%@')", Value1, Value2];
NSLog(@"%@", jsCallBack);
[self.viewController.webView stringByEvaluatingJavaScriptFromString:jsCallBack];
}
I read posts in SO and few other blogs that didFinishLaunchingWithOptions
is something that would help me handle the notification when the app is not running at all.
This link has info but am not sure about the implementation for my scenario.
Please could someone help me on how to use didFinishLaunchingWithOptions
in my case? What all I need is to get the custom data fields, pass them to my JSCallBack even when the app is not running.
Should I have both didReceiveRemoteNotification
and didFinishLaunchingWithOptions
in my delegate.m? Also, when I am also using didFinishLaunchingWithOptions
in my delegate.m, what changes should I make in delegate.h?
UPDATE 1: I understood that, when the app is terminated, one cannot get access to the payload. And, when app is in foreground or background, it is the didReceiveRemoteNotification
that works when there is a push notification.
But, I am not able to invoke my JS callback function when I received the notification and I tapped on it while the app is in background.
I need some help on how to handle this.