I'm using Cordova and the plugin phonegap-plugin-push, when my app is in foreground I don't see the notification alert. What I have to do? (I know the way to do it on Android platform (setting "forceShow": true in the method init of PushNotification) but this works only for Android) Thank you in advance for your replies.
2
votes
3 Answers
1
votes
If u don't want to touch ios native things, then you can display your own custmize html/css Banner (like iOS push Baner) in following method :
push.on('notification', function(data) {
If(platform == "iOS" && data.additionalData.foreground){
// Show your Baner here
// U can also define call back on clicking of that banner
//Like navigation to respective page or close that banner
});
0
votes
Denise,
Notification doesn't work in the foreground. It only works in the background. Do handle it in the foreground you need to implement the logic in the delegate method. Below is the Objective C code snippet to show the notification in the foreground.
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
application.applicationIconBadgeNumber = 0;
//self.textView.text = [userInfo description];
// We can determine whether an application is launched as a result of the user tapping the action
// button or whether the notification was delivered to the already-running application by examining
// the application state.
if (application.applicationState == UIApplicationStateActive)
{
// Nothing to do if applicationState is Inactive, the iOS already displayed an alert view.
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Did receive a Remote Notification" message:[NSString stringWithFormat:@"Your App name received this notification while it was running:\n%@",[[userInfo objectForKey:@"aps"] objectForKey:@"alert"]]delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alertView show];
}
}
It will help you for your problem.
0
votes
In iOS if your app is in foreground, push notification alert will not show. To achieve it, you should write code for alert in push notification receive delegate if your application is in foreground. To know application state in iOS this is the code.
+(BOOL) runningInForeground
{
UIApplicationState state = [UIApplication sharedApplication].applicationState;
return state == UIApplicationStateActive;
}