当应用程序处于前台时 OneSignal 不显示通知

OneSignal does not showing notification when app is in foreground

我用 onesignal 集成了我的 flutter 应用程序,当应用程序在后台时它工作完美,但在前台它收到通知但不显示它不知道为什么?

log

flutter: OSNotificationReceivedEvent complete with notification: Instance of 'OSNotification'
VERBOSE: finishProcessingNotification: Fired!
VERBOSE: Notification display type: 7
VERBOSE: notificationReceived called! opened: NO
VERBOSE: finishProcessingNotification: call completionHandler with options: 7

前台处理程序

  OneSignal.shared.setNotificationWillShowInForegroundHandler(
      (OSNotificationReceivedEvent event) {
    event.complete(event.notification);
  });

给你:

OneSignal.shared
        .setNotificationWillShowInForegroundHandler((OSNotificationReceivedEvent event) {
           print('FOREGROUND HANDLER CALLED WITH: ${event}');
           /// Display Notification, send null to not display
           event.complete(null);
          
           this.setState(() {
           _debugLabelString =
              "Notification received in foreground notification: \n${event.notification.jsonRepresentation().replaceAll("\n", "\n")}";
      });
    });  

你可以找到一个full example here