Reputation: 103
I have a cordova app (codova (3.4.0) running on iOS and soon also on Android. Push notifications are implemented and working. I'm having troubles detecting when the app was started through a push notification and redirecting the application to the right page.
Note: This doesn't concern starting the app from a push notification when the app is running in the background. Only when the app is completely closed!
I now have the following workflow:
Regular startup:
Cold app startup from push notification:
As you can see the cold app startup scenario going to the startup view, which is unnecessary and causes the user to wait for the first view to load, only to be redirected again.
The problem is that when deviceready fires, my javascript code isn't aware of the coming push notification yet, so i'm looking for a way around this.
Is there a way to maybe pass extra parameters to the deviceready cordova event? Or does anybody have another idea or solution to tackle this problem?
Upvotes: 6
Views: 3647
Reputation: 103
I eventually managed to solve this. It seems that during startup, in the following method the launchOptions parameter indicates if the app was started from a push notification or not.
- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions
{
...
}
In the method above i set the startup url for my application and provide an extra url parameter if the app was started from a push notification. So i now have the following scenario which solves my problem:
Hope it helps someone.
Upvotes: 1
Reputation:
I guess you could workaround:
var coldstart = true;
// Update flag if app coldstart
document.addEventListener("pause", function() {
coldstart = false;
}, false);
Upvotes: 2