我有一个cordova应用程序,使用cordova-plugin-firebasex来管理移动的上的推送通知。
我有以下实现来检查通知权限,授予权限和保存FCM令牌。它适用于iOS设备和Android设备之前的Android 12.
checkNotificationPermissions = (requested) => {
console.log("check permissions");
window.FirebasePlugin.hasPermission(function(hasPermission) {
console.log("has permission: " + hasPermission);
if (hasPermission) {
console.log("Remote notifications permission granted");
// Granted
window.FirebasePlugin.getToken(function(token){
console.log("Got FCM token: " + token)
}, function(error) {
console.log("Failed to get FCM token", error);
});
} else if (!requested) {
// Request permission
console.log("Requesting remote notifications permission");
window.FirebasePlugin.grantPermission(function(hasPermission){
console.log("Permission was " + (hasPermission ? "granted" : "denied"));
});
} else {
// Denied
console.log("Notifications won't be shown as permission is denied");
}
})
window.FirebasePlugin.onMessageReceived(function(message){
if(message && message.url){
history.push(message.url)
}
}, function(error){
console.log("Error on message received " + error);
})
}
字符串
checkNotificationPermissions被正确调用,window.FirebasePlugin被正确初始化(如果我在函数的顶部console.log它,则对象存在)。然而,当在Android 13物理设备上运行时,代码似乎永远不会到达window.FirebasePlugin.hasPermission回调(既不成功也不错误)。
我已经根据新的Android 13要求在我的config.xml中添加了POST_NOTIFICATIONS权限:
<config-file target="AndroidManifest.xml" parent="/*">
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
</config-file>
型
我在奔跑
- cordova 12.0.0(cordova-ios 6.3.0 & cordova-android 12.0.0)
- cordova-plugin-firebasex 16.1.0
- cordova-plugin-statusbar 3.0.0
- 三星Galaxy A33与Android 13
有办法吗?谢谢你的帮助。
编辑我在Android 12和13上运行时在logcat中发现了此日志,表明exec()函数经常被忽略。不知道为什么...
CordovaBridge: Ignoring exec() from previous page load.
型
应显示以下日志:
- 检查权限
- 有权限:假的
- 请求远程通知权限
- 批准了
我得到的日志:
- 检查权限
1条答案
按热度按时间ohfgkhjo1#
我最终找到了错误的根源和解决方案。
忽略exec()错误:
字符串
源自另一个错误:
型
根据这篇文章https://github.com/ionic-team/cordova-plugin-ionic-webview/issues/600#issuecomment-771246329,我必须确保我将我的主机名和方案列入白名单。我已经为这个方案做过了,但是在config.xml中添加主机名解决了这个问题。
型