0

我将我的颤振应用程序与一个信号集成在一起,当应用程序在后台时它工作得很好,但在前台它正在接收通知但不知道为什么?

日志

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);
  });
4

1 回答 1

2

干得好:

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")}";
      });
    });  

你可以在这里找到一个完整的例子

于 2021-10-29T19:12:07.140 回答