我正在使用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); });
在离子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));
}
有什么建议吗? 谢谢
答案 0 :(得分:0)
这解决了我的问题:
var messageToSend = {
data: {
title: title,
body: message,
priority: constantsManager.FirebaseNotificationPriority
},
topic: topic
};