【问题标题】:Ionic 3 - Vibration is not working but the sound isIonic 3 - 振动不起作用,但声音正常
【发布时间】:2018-10-31 15:12:49
【问题描述】:

我正在使用 ionic 3 构建应用程序,现在我想向用户发送一些通知。

当我收到通知时,声音正常,但振动没有。

我在两种不同的设备上进行了测试。

    var serviceAccount = require(constantsManager.FirebaseKey);

    if (!admin.apps.length) {
        admin.initializeApp({
            credential: admin.credential.cert(serviceAccount),
            databaseURL: constantsManager.FirebaseDataUrl
        });
    }

    var messageToSend = {
        android: {
            priority: constantsManager.FirebaseNotificationPriority,
            notification: {
                title: title,
                body: message,
                sound: 'default',
            }
        },
        topic: topic
    };

    admin.messaging().send(messageToSend)
        .then(function (response) { console.log('Push success: ' + JSON.stringify(response)); })
        .catch(function (error) { console.log('Push Error: ' + error); });

在 ionic 3 中我有:

pushSetup() {
const options: PushOptions = {
  android: {
    senderID: Constants.NOTIFICATION_SENDER_ID,
    sound: Constants.NOTIFICATION_SOUND,
    vibrate: Constants.NOTIFICATION_VIBRATE,
    topics: Constants.NOTIFICATION_TOPICS,
    icon: Constants.NOTIFICATION_ICON
  },
  ios: {
    sound: Constants.NOTIFICATION_SOUND,
    topics: Constants.NOTIFICATION_TOPICS,

  }
};

const pushObject: PushObject = this.push.init(options);

pushObject.on('notification').subscribe((notification: any) => this.showMessageToUser(notification.title + " " + notification.message));

pushObject.on('registration').subscribe((registration: any) => console.log('Device registered', registration));

pushObject.on('error').subscribe(error => console.error('Error with Push plugin', error));

}

有什么建议吗? 谢谢

【问题讨论】:

    标签: ionic-framework push-notification ionic3


    【解决方案1】:

    这解决了我的问题:

    var messageToSend = {
            data: {
                title: title,
                body: message,
                priority: constantsManager.FirebaseNotificationPriority
            },
    
            topic: topic
        };
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-13
      • 2021-10-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-06
      • 1970-01-01
      相关资源
      最近更新 更多