当应用程序从nativescript插件firebase通知消息打开时,我的应用程序在Android上崩溃返回按钮点击
我正在开发一个接收[nativescript plugin firebase]通知的nativescript angular应用程序 这个项目是最新的。package.json包含以下行:当应用程序从nativescript插件firebase通知消息打开时,我的应用程序在Android上崩溃返回按钮点击,nativescript,nativescript-angular,nativescript-plugin,Nativescript,Nativescript Angular,Nativescript Plugin,我正在开发一个接收[nativescript plugin firebase]通知的nativescript angular应用程序 这个项目是最新的。package.json包含以下行: “tns安卓”:{ “版本”:“5.4.0” }, “tns核心模块”:“~5.4.0”, “@angular/core”:“~8.0.0” nativescript插件firebase“^9.0.1” 通知正常,但在以下情况下,点击通知消息时应用程序崩溃: 应用程序已打开(在前台) 设备已关闭 然后点击锁
“tns安卓”:{
“版本”:“5.4.0”
},
“tns核心模块”:“~5.4.0”,
“@angular/core”:“~8.0.0”
nativescript插件firebase“^9.0.1” 通知正常,但在以下情况下,点击通知消息时应用程序崩溃:
- 应用程序已打开(在前台)
- 设备已关闭
- 然后点击锁屏通知消息
- 应用程序崩溃了
- 并显示:
An uncaught Exception occurred on 'main' thread. java.lang.RuntimeException: Unable to destroy activity
ngOnInit(): void {
/// *** Firebase Cloud Messaging ***
firebase.addOnMessageReceivedCallback(
(message) => {
const that = this;
let contentId: string = "";
if (message.foreground) {
/** If the app is already open, show a dialog message. **/
confirm({
title: message.title,
message: message.body,
okButtonText: "Open",
cancelButtonText: "Cancel"
}).then(function (result) {
// result argument is boolean
if (result) {
if (message.data.contentId) {
contentId = message.data.contentId;
if (parseInt(contentId) > 0) {
that.routerExtensions.navigate(["/car-detail/" + contentId], { clearHistory: false });
}
}
}
// console.log("Dialog result: " + result);
});
}
else {
/** Else if the message arrived when the app is in the background, this code is executed when the user taps on the notification. **/
if (message.data.contentId) {
contentId = message.data.contentId;
if (parseInt(contentId) > 0) {
this.routerExtensions.navigate(["/car-detail/" + contentId], { clearHistory: false });
}
}
}
}
)
if (this.authenticationService.FirebaseToken == undefined || this.authenticationService.FirebaseToken == null) {
firebase.init({
// Optionally pass in properties for database, authentication and cloud messaging, see their respective docs.
onPushTokenReceivedCallback: function (token: any) {
console.log("Firebase push token: " + token);
}
, showNotificationsWhenInForeground: true
}).then(
() => {
console.log("firebase.init done");
},
error => {
console.log(`firebase.init error: ${error}`);
}
);
firebase.getCurrentPushToken().then((token: string) => {
// may be null if not known yet
console.log(`Current push token: ${token}`);
this.authenticationService.FirebaseToken = token;
});
}
// *** / Firebase Cloud Messaging ***
}
但是这需要太多的时间。不确定我们是否在同一页上,我的意思是在调用
that.routerExtensions.navigate()
之前超时。我按照您提到的方式执行了。但在另一个分支上,则是{},因为该应用程序被最小化,并在后台考虑。行为没有改变。你能分享一个最小的样本项目吗?我恐怕不能。所有页面都需要生成中标通知书。但我可以提供app.apk。还有一个浏览器链接,它会触发出价过高通知。但这需要太多时间。我不确定我们是否在同一个页面上,我的意思是在调用that.routerExtensions.navigate()
之前有一个超时。我按照你提到的方式做了。但在另一个分支上,则是{},因为该应用程序被最小化,并在后台考虑。行为没有改变。你能分享一个最小的样本项目吗?我恐怕不能。所有页面都需要生成中标通知书。但我可以提供app.apk。以及一个浏览器链接,用于触发出价高于通知。