taivo / parse-push-plugin

Push notification plugin for Cordova/Phonegap/ionic on Parse platform
118 stars 102 forks source link

Hide/show iOS banner push in open app #100

Open youstartlabs opened 7 years ago

youstartlabs commented 7 years ago

Hi, Thanks for the great plugin. I am using the latest release of the plugin V1.0.7 . I am developing on iOS 10.2 . My issue is related to banner push in iOS. When my app is open, I receive notifications properly, but each time a notification drops from above, similar to what happens when the app is closed. This becomes a trouble when I am sending and receiving push for a chat. Every message drops a notification from top and it takes time for it to disappear. I am wondering if there is any setting available in the plugin to control hiding/showing of the banner notification when the app is open. If not in plugin, is there any iOS native setting I can change in a file or Xcode which allows control over the banner push. This SO issue relates to similar, but opposite problem, where they want to show the banner push.

magickaito commented 7 years ago

Did you find a solution in the end? I am facing a similar problem, I do not want the notification banner when the app is opened.

magickaito commented 7 years ago

In case anyone facing same problem, I manage to hide the notification by editing userNotificationCenter:willPresentNotification method in ParsePushPlugin.m:

-(void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:
(UNNotification *)notification withCompletionHandler:(void (^)
(UNNotificationPresentationOptions))completionHandler {
NSLog(@"User info %@", notification.request.content.userInfo);

UIApplication *application = [UIApplication sharedApplication];
[self jsCallback:notification.request.content.userInfo withAction:(application.applicationState == UIApplicationStateActive) ? @"RECEIVE" : @"OPEN"];

//added this line to hide the notification
completionHandler(UNNotificationPresentationOptionNone);

//commented out this line to hide the notification
//completionHandler(UNNotificationPresentationOptionAlert);
}