【发布时间】:2019-02-04 06:45:13
【问题描述】:
我在 Nativescript 应用程序中使用 firebase 时遇到问题,当我使用 android 时,它运行良好,但无法使用 IOS。问题出在消息发送上。 我在客户端使用推送插件
这是IOS客户端使用pushPlugin的注册部分
const iosSettings:any = {
badge: true,
sound: true,
alert: true,
interactiveSettings: {
actions: [{
identifier: 'READ_IDENTIFIER',
title: 'Read',
activationMode: "foreground",
destructive: false,
authenticationRequired: true
}, {
identifier: 'CANCEL_IDENTIFIER',
title: 'Cancel',
activationMode: "foreground",
destructive: true,
authenticationRequired: true
}],
categories: [{
identifier: 'READ_CATEGORY',
actionsForDefaultContext: ['READ_IDENTIFIER', 'CANCEL_IDENTIFIER'],
actionsForMinimalContext: ['READ_IDENTIFIER', 'CANCEL_IDENTIFIER']
}]
},
notificationCallbackIOS: (message: any) => {
alert(JSON.stringify(message));
}
};
pushPlugin.register(iosSettings, (token: string) => {
// update the token in the server
alert("Device registered. Access token: " + token);
});
}
}, (errorMessage: any) => {
alert("Device NOT registered! " + JSON.stringify(errorMessage));
});
这就是我收到推送通知令牌的方式, 在我使用推送应用程序时获得令牌后一切正常,我在 IOS 设备中收到通知 但问题是当我试图从服务器发送通知时!
我得到这个错误:
提供的注册令牌无效。确保它与 客户端应用通过 FCM 注册收到的注册令牌。
我的服务器中的节点代码
var payload = {
data: {
targetId:userToken,
body: "some text"
}
};
var options = {
priority: "high",
contentAvailable: true,
timeToLive: 60 * 60 * 24
};
Admin.messaging().sendToDevice(userToken, <any>payload,options)
.then((response) => {
console.log('notification arrived successfully', response.results[0]);
})
.catch((error) => {
console.log('notification failed', error);
});
【问题讨论】:
标签: ios node.js firebase firebase-cloud-messaging nativescript