【问题标题】:How to use Pushwoosh in Ionic 5 project with capacitor如何在带电容器的 Ionic 5 项目中使用 Pushwoosh
【发布时间】:2021-01-14 01:07:09
【问题描述】:

大家好,我正在将应用程序从 ionic 1 迁移到 ionic 5,我需要集成 pushwoosh 通知服务,我的项目开始时没有使用cordova,而是使用电容器,但我找不到有关如何将此服务集成到 ionic 5 应用程序中。

请,我们已经知道您可以使用cordova,但是在使用cordova plugin add pushwoosh-cordova-plugin@8.0.0 时,它会给您以下消息:

Current working directory is not a Cordova-based project.

因为正如我之前所说,它是一个电容器项目而不是一个 Cordovan 项目,顺便说一句,我已经使用 ionic integrations enable cordova

所以...如果有人可以帮助我们,那将非常有帮助。

【问题讨论】:

标签: ionic-framework capacitor pushwoosh


【解决方案1】:

好吧,伙计们,在尝试将 Pushwoosh 集成到 ionic 5 应用程序中对我来说这是不可能的,

如果一切设置正确,将会发生以下情况:

  1. 您的应用将正确连接到 Pushwoosh
  2. 您的应用会在 pushwoosh 中正确注册您的设备

但您的应用不会听取 Pushwoosh 官方文档提供的监听器

document.addEventListener('push-receive',
    function (event) {
        var message = (<any>event).notification.message;
        var userData = (<any>event).notification.userdata;
                              
        alert("Push message received: " + message);
        console.info(JSON.stringify((<any>event).notification));
                              
        //dump custom data to the console if it exists
        if (typeof (userData) != "undefined") {
          console.warn('user data: ' + JSON.stringify(userData));
        }
      }
   );

这在 ionic 5 应用程序中不起作用??

这确实有效:

import { Component, OnInit } from '@angular/core';

import {
  Plugins,
  PushNotification,
  PushNotificationToken,
  PushNotificationActionPerformed,
} from '@capacitor/core';

const { PushNotifications } = Plugins;

@Component({
  selector: 'app-home',
  templateUrl: 'home.page.html',
  styleUrls: ['home.page.scss'],
})
export class HomePage implements OnInit {
  ngOnInit() {
    console.log('Initializing HomePage');

    // Request permission to use push notifications
    // iOS will prompt user and return if they granted permission or not
    // Android will just grant without prompting
    PushNotifications.requestPermission().then(result => {
      if (result.granted) {
        // Register with Apple / Google to receive push via APNS/FCM
        PushNotifications.register();
      } else {
        // Show some error
      }
    });

    PushNotifications.addListener(
      'registration',
      (token: PushNotificationToken) => {
        alert('Push registration success, token: ' + token.value);
      },
    );

    PushNotifications.addListener('registrationError', (error: any) => {
      alert('Error on registration: ' + JSON.stringify(error));
    });

    PushNotifications.addListener(
      'pushNotificationReceived',
      (notification: PushNotification) => {
        alert('Push received: ' + JSON.stringify(notification));
      },
    );

    PushNotifications.addListener(
      'pushNotificationActionPerformed',
      (notification: PushNotificationActionPerformed) => {
        alert('Push action performed: ' + JSON.stringify(notification));
      },
    );
  }
}

我尝试将 Pushwoosh 与电容器结合使用,但生成的设备令牌不同,所以我仍然没有收到通知。

在一天结束时,经过数小时和数天的工作,我别无选择,只能使用 firebase,现在一切都变得更好了。

【讨论】:

    猜你喜欢
    • 2021-03-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-23
    • 1970-01-01
    • 2021-04-12
    相关资源
    最近更新 更多