使用 OneSignal 的 Capacitor 3 应用程序中未显示前景通知

问题描述 投票:0回答:1

我有一个使用 Capacitor 3.2.3 的 Ionic 5.x 应用程序。我们使用

onesignal-cordova-plugin
发送推送通知并注册设备以接收推送通知。

当应用程序在后台时,我们能够毫无问题地接收通知。但是,当应用程序位于前台时,我无法接收通知。我知道在 iOS 10 之后使用应用程序需要实现 UNUserNotificationCenterDelegate,但即使我实现了该功能,我仍然无法在前台接收通知。

我已经实现了

UNUserNotificationCenterDelegate

func userNotificationCenter(_ center: UNUserNotificationCenter,
                                    willPresent notification: UNNotification,
                                    withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
     print("Push notification received in foreground.")
     completionHandler([.alert, .sound, .badge])
  }

但是当我设置断点时,这个函数永远不会被调用。

我没有使用任何电容器推送通知包。

  "dependencies": {
    "@angular/animations": "^12.2.6",
    "@angular/cdk": "^12.2.6",
    "@angular/common": "^12.2.6",
    "@angular/core": "^12.2.6",
    "@angular/forms": "^12.2.6",
    "@angular/material": "^12.2.6",
    "@angular/platform-browser": "^12.2.6",
    "@angular/platform-browser-dynamic": "^12.2.6",
    "@angular/router": "^12.2.6",
    "@capacitor-community/apple-sign-in": "^1.0.1",
    "@capacitor-community/facebook-login": "^3.1.1",
    "@capacitor-community/firebase-analytics": "^1.0.0",
    "@capacitor/android": "^3.2.3",
    "@capacitor/app": "^1.0.3",
    "@capacitor/browser": "^1.0.3",
    "@capacitor/core": "^3.2.3",
    "@capacitor/device": "^1.0.3",
    "@capacitor/haptics": "^1.0.3",
    "@capacitor/ios": "^3.2.3",
    "@capacitor/keyboard": "^1.0.3",
    "@capacitor/splash-screen": "^1.1.2",
    "@capacitor/status-bar": "^1.0.3",
    "@capacitor/storage": "^1.2.0",
    "@innomobile/capacitor-branch-deep-links": "^1.0.0",
    "@ionic-native/core": "^5.34.0",
    "@ionic-native/in-app-purchase-2": "^5.34.0",
    "@ionic-native/native-storage": "^5.34.0",
    "@ionic-native/splash-screen": "^5.34.0",
    "@ionic-native/status-bar": "^5.34.0",
    "@ionic/angular": "^5.6.12",
    "@ionic/core": "^5.6.12",
    "@ionic/pwa-elements": "^1.5.1",
    "@types/jquery": "^3.5.1",
    "capacitor-rate-app": "^1.1.0",
    "cc.fovea.cordova.purchase": "^10.5.3",
    "cordova-plugin-nativestorage": "^2.3.2",
    "moment": "^2.27.0",
    "ngx-moment": "^4.0.1",
    "onesignal-cordova-plugin": "^3.0.0",
    "rxjs": "~6.5.1",
    "smoothscroll-polyfill": "^0.4.4",
    "swiper": "^7.0.6",
    "tslib": "^2.0.0",
    "uuid": "^8.1.0",
    "zone.js": "~0.11.4"
  },
ios ionic-framework push-notification onesignal capacitor
1个回答
0
投票

我遇到了同样的问题 - 您是否找到了为什么会发生这种情况以及如何解决它的答案?

© www.soinside.com 2019 - 2024. All rights reserved.