在IOS上使用cordova插件@havesource/cordova-plugin-push时未显示通知

mum43rcc  于 2022-11-15  发布在  iOS
关注(0)|答案(1)|浏览(182)

我需要帮助与firebase通知不工作在我的iPad与PWA
cordova 版本:11.
我正在使用@havesource/cordova-plugin-push插件。
这是我发来信息。

{
    "to" : "/topics/user_topic",
    "notification": {
        "title" : "this is test title 4 IOS",
        "body": "this is test body"
    },
    "content_available": true
}

这是我在PWA中插件初始化代码:

initPush() {
    console.log('Initializing push plugin.');
    let config = {
      android: {
        vibrate: true,
        clearNotifications: true
      },
      ios: {
        fcmSandbox: true,
        alert: true,
        badge: true,
        sound: true
      }
    }

    let push  = PushNotification.init(config);
    PushNotification.hasPermission(
      () => {
      console.log("Notification permission granted");
        push.subscribe("user_topic", () => {
          console.log("Subscribed to user_topic");},
          () => {
          console.log("cannot subscribe");
          });
        push.on(
        'notification',
        (data: any) => {
          console.log(data);
        });
        push.on(
          'error',
          (data: any) => {
            console.log(data);
          });
      },
      () => {
        console.log("not permitted to receive notifications!");
      }
    );
  }

这是我在日志中看到

2022-04-07 10:39:58.394281+0200 MobileApp[15262:495753] PushPlugin skip clear badge
2022-04-07 10:39:58.869358+0200 MobileApp[15262:495753] The preference key "AutoHideSplashScreen" is not defined and will default to "TRUE"
2022-04-07 10:39:59.045482+0200 MobileApp[15262:495753] Initializing push plugin.
2022-04-07 10:39:59.095513+0200 MobileApp[15262:495753] Notification permission granted
2022-04-07 10:39:59.095776+0200 MobileApp[15262:495753] subscribe from topic: user_topic
2022-04-07 10:39:59.110737+0200 MobileApp[15262:495753] Successfully subscribe to topic user_topic
2022-04-07 10:39:59.110975+0200 MobileApp[15262:495753] THREAD WARNING: ['PushNotification'] took '15.206055' ms. Plugin should use a background thread.
2022-04-07 10:39:59.121693+0200 MobileApp[15262:495753] Push Plugin VoIP missing or false
2022-04-07 10:39:59.121896+0200 MobileApp[15262:496009] Push Plugin register called
2022-04-07 10:39:59.121960+0200 MobileApp[15262:496009] PushPlugin.register: setting badge to false
2022-04-07 10:39:59.122359+0200 MobileApp[15262:496009] PushPlugin.register: clear badge is set to 0
2022-04-07 10:39:59.122415+0200 MobileApp[15262:496009] PushPlugin.register: better button setup
2022-04-07 10:39:59.136426+0200 MobileApp[15262:496009] FCM Sender ID 1079642262479
2022-04-07 10:39:59.136848+0200 MobileApp[15262:495753] Subscribed to user_topic
2022-04-07 10:39:59.139873+0200 MobileApp[15262:496009] Using FCM Notification
2022-04-07 10:39:59.143171+0200 MobileApp[15262:496009] Using FCM Sandbox
2022-04-07 10:39:59.147152+0200 MobileApp[15262:496011] 6.32.0 - [Firebase/Core][I-COR000003] The default Firebase app has not yet been configured. Add `[FIRApp configure];` (`FirebaseApp.configure()` in Swift) to your application initialization. Read more: some url.
2022-04-07 10:39:59.180689+0200 MobileApp[15262:496011] 6.32.0 - [Firebase/Core][I-COR000003] The default Firebase app has not yet been configured. Add `[FIRApp configure];` (`FirebaseApp.configure()` in Swift) to your application initialization. Read more: some url.
2022-04-07 10:39:59.399222+0200 MobileApp[15262:496017] 6.32.0 - [Firebase/Messaging][I-FCM001000] FIRMessaging Remote Notifications proxy enabled, will swizzle remote notification receiver handlers. If you'd prefer to manually integrate Firebase Messaging, add "FirebaseAppDelegateProxyEnabled" to your Info.plist, and set it to NO. Follow the instructions at: some google url #method_swizzling_in_firebase_messaging to ensure proper integration.
2022-04-07 10:39:59.465435+0200 MobileApp[15262:495753] Remote instance ID (FCM Registration) Token: dEEoc-ZTw0uPn8W0gWYIIk:APA91bFoLoSDlEhQjtdTnkri7ObWQtpxKvrRQhb88OY_t5uJOCawpyD2zl59GbsMqEVj8W0iJgkIsZN_ZywTUkOfHiN1mLyxTInYkxkcjdBI2H4KCTugkFUWRVTjKP3P4OPELLqWHu3Y
2022-04-07 10:39:59.465736+0200 MobileApp[15262:495753] The FCM registration token needs to be changed.
2022-04-07 10:39:59.467143+0200 MobileApp[15262:495753] Remote instance ID (FCM Registration) Token: dEEoc-ZTw0uPn8W0gWYIIk:APA91bFoLoSDlEhQjtdTnkri7ObWQtpxKvrRQhb88OY_t5uJOCawpyD2zl59GbsMqEVj8W0iJgkIsZN_ZywTUkOfHiN1mLyxTInYkxkcjdBI2H4KCTugkFUWRVTjKP3P4OPELLqWHu3Y
2022-04-07 10:40:00.460113+0200 MobileApp[15262:495753] The FCM registration token needs to be changed.
2022-04-07 10:40:00.461093+0200 MobileApp[15262:495753] Remote instance ID (FCM Registration) Token: fWmg0xS3I0xslBHpaLBOvM:APA91bGKYgfF8Lc6liN_-t3iTgIHnM9WuEnQLjh65_zFQcwfSvTwh8pTSb6honrpCM78B10oy4-qqNMTV9EZVqdvV_J7jyWi_CzhEKz15-9qk5yMJE4DOvHKG6vlFPqjtgkhvF-b3nv_
2022-04-07 10:40:04.686428+0200 MobileApp[15262:495753] Push Plugin register success: {length = 32, bytes = 0xc79fbd12 1e49eac0 ffb03532 1e77f52f ... 9ee9d858 daa00a98 }
2022-04-07 10:40:04.992756+0200 MobileApp[15262:495753] active
2022-04-07 10:40:04.993124+0200 MobileApp[15262:495753] PushPlugin skip clear badge
2022-04-07 10:40:05.008727+0200 MobileApp[15262:495753] Push Plugin register success: {length = 32, bytes = 0xc79fbd12 1e49eac0 ffb03532 1e77f52f ... 9ee9d858 daa00a98 }

此外,我的应用程序还设置了推送功能

日志显示发送者ID已设置,这意味着插件已连接到firebase云消息传递,日志还显示应用已订阅firebase云消息传递上的user_topic主题。
我在日志中看不到任何错误,所以我不确定下一步该在哪里查找为什么我没有收到任何推送通知。
通知在Android设备上工作。
任何帮助与想法感激不尽。
我甚至用所有的代码创建了github project

laawzig2

laawzig21#

解决方案1:

我已经改变了主题是在init上订阅的,而不是在hasPermission promise中订阅的。
我撤了:

push.subscribe("user_topic", () => {
    console.log("Subscribed to user_topic");},
    () => {
    console.log("cannot subscribe");
   });

并添加了

let config = {
  android: {
    vibrate: true,
    clearNotifications: true,
    topics: ['user_topic']
  },
  ios: {
    fcmSandbox: true,
    alert: true,
    badge: true,
    sound: true,
    topics: ['user_topic']
  }
}

解决方案2:

移动此代码

push.subscribe("user_topic", () => {
    console.log("Subscribed to user_topic");},
    () => {
    console.log("cannot subscribe");
   });

注册事件承诺

push.on('registration',
  (data: any) => {
    console.log("Got registration data: %o", data);
    console.log("will subscribe to topic: [user_topic]");
    push.subscribe("user_topic", () => {
        console.log("Subscribed to [user_topic]");},
      () => {
        console.log("cannot subscribe");
      });
 });

相关问题