本地通知在单击按钮时使 Ionic/Angular/Cordova 应用程序崩溃

问题描述 投票:0回答:2

这是我在 home.page.ts 文件中与 Ionic/Cordova 本地通知插件一起使用的代码:

 notifs(time) {
    this.localNotifications.schedule({
       id: 1,
       title: 'Test App',
       text: 'Enter Text',
       icon: '../test.png'
       trigger: {at: new Date(new Date().getTime() + 3600)},
    });
  }

在我的 html 模板中,单击此按钮可以调用上述函数:

<ion-button (click)="notifs(12)" [fill]="fill" slot="">Hours</ion-button>

每次单击此按钮时,Android 应用程序都会崩溃。

我想点击该按钮,这将在每天同一时间的延迟时间触发电话通知(即使用户不在应用程序上)。我怎样才能做到这一点?

更新: 我删除了 id、图标和按钮单击,因此如下所示:

 notifs(time) {
    this.localNotifications.schedule({
       title: 'Test App',
       text: 'Enter Text',
       trigger: {at: new Date(new Date().getTime() + 3600)}
    });
  }

现在的问题是,每次触发触发器并且应该发生通知时,应用程序都会崩溃。 通知在 iOS 上运行良好。 我尝试使用 Chrome android 调试器进行调试,但没有任何反应。

android cordova ionic-framework notifications local
2个回答
0
投票

我也有类似的问题。每次我尝试安排通知时,我的 Android 应用程序都会崩溃,最后我发现这是因为触发器属性。

我的案例是:

trigger: { every: { hour: this.hour, minute: this.minute } }

如果 this.hour 或 this.min 不是有效值,应用程序就会崩溃。尝试更改属性“at”中指定的值,表达式“new Date(new Date().getTime() + 3600”可能会为此属性生成无效值。


0
投票

我在 2023 年 8 月 2 日遇到了这个问题,这是我找到的解决方案...插件 https://github.com/katzer/cordova-plugin-local-notifications 在 android 12 (API 32) 中不起作用) 和 13 (API 33) 你必须安装 fquirin 的 fork。

运行 1-cordova插件添加https://github.com/fquirin/cordova-plugin-local- 通知.git

2- npm install @awesome-cordova-plugins/local-notifications

注意:API 32 和 API 33 需要用户的权限才能显示通知,不要忘记将此行添加到 Platform/android/App/Src/Main 文件夹中的 AndroidManifest.xml 中

希望对你有帮助!

© www.soinside.com 2019 - 2024. All rights reserved.