0

hi I used this UNUserNotificationCenterDelegate for avoiding alert notification while app is in foreground with this function

-(void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler  API_AVAILABLE(ios(10.0)){
    completionHandler(UNNotificationPresentationOptionAlert);
}

but I get notification with both option Alert & banner how can I remove alert while app is in foreground?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
MahdiM
  • 41
  • 9

2 Answers2

0

You have to apply the condition in the willPresent Method, to check the state of the App, and if State is UIApplecationStateForeGround then do nothing , else they follow UNNotificationPresentationOptionAlert .

MayankSengar
  • 284
  • 5
  • 19
0

I found how to fix there is a option for one signal init to avoid showing alert

[OneSignal initWithLaunchOptions:launchOptions appId:@"YOURE_KEY" handleNotificationReceived:nil handleNotificationAction:nil
                            settings:@{kOSSettingsKeyInAppAlerts:@NO}];

and for showing as banner you have to add this code

-(void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler  API_AVAILABLE(ios(10.0)){
    completionHandler(UNNotificationPresentationOptionAlert);
}
MahdiM
  • 41
  • 9