我在我的 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));
});
这就是我收到推送通知 token 的方式, 在我使用推送器应用程序时获得 token 后,一切正常,我在 IOS 设备中收到通知 但问题是当我试图从服务器发送通知时!。
我收到这个错误:
Invalid registration token provided. Make sure it matches the registration token the client app receives from registering with FCM.
我服务器中的 Node 代码
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 的注册 token 与 android 的不同。我遇到了你遇到的同一堵墙。 IOS推送通知需要使用https://github.com/node-apn/node-apn
。和 firebase
用于 android 通知。您可以通过保存 token 在后端执行逻辑。带有一个名为 type
的字段,如果 ios 你使用 node-apn
并且如果 android 使用 sendToDevice
则它是 ios 或 android
由 Firebase 提供。
这就是我目前在我当前的 nativescript 项目中使用的,我正在处理的涉及推送通知。希望对你有帮助,伙计。
关于ios - 原生脚本 | Firebase 通知不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52078099/