NativeScript / NativeScript/plugins

[@nativescript/local-notifications] Scheduling a notification using the "at" property results in the notification being severly late

未关闭
#529 4 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

主要语言
TypeScript
星标
206
派生
123
平均合并
2 天 1 小时
30 天内合并 PR
1

描述

  • Android 13, targeting API level 33
  • @nativescript/core 8.5.7
  • @nativescript/local-notifications 6.1.1

This has not been tested on iOS yet, but will be soon, and I'll update this issue with the results once that has been done. It has been replicated on both a Samsung phone and tablet.

While trying to make use of the LocalNotifications.schedule() functionality, the notification arrives as expected, but ends up being significantly late. For instance, when trying to schedule a notification a minute into the future:

public async addScheduledNotification(notificationId: string) {
    const notification = NOTIFICATION_TYPES.find((n => n.id == notificationId));
    const targetStart = new Date(new Date().getTime() + 60 * 1000);
    console.log(`target start: ${targetStart}`);
    console.log(`getTime: ${targetStart.getTime()}`);
    console.log(await LocalNotifications.schedule([{
        id: Number.parseInt(notification.id),
        title: 'My App',
        body: notification.body,
        // interval: 'day' as ScheduleInterval,
        channel: 'MyApp',
        priority: 2,
        at: targetStart
    }]));
    console.log(await LocalNotifications.getScheduledIds());
}

Output:

  JS: CONSOLE LOG: target start: Tue Sep 05 2023 21:30:00 GMT-0400 (EDT)
  JS: CONSOLE LOG: getTime: 1693963800000
  JS: CONSOLE LOG: [0]
  JS: CONSOLE LOG: [0]

the notification will arrive about 1 minute and forty five seconds from the time the code runs. I've tried different use cases and the delay can be as large as 15 minutes to an hour. Lowering the delay to ten seconds after the code runs results in it arriving on time. Leaving the at parameter out results in the notification being shown immediately as expected. There doesn't seem to be much of a difference whether the screen is on or off when the notification is supposed to fire. Seeing as the screen is often on and there's still a delay, I don't suspect the issue is due to a battery saver or Doze.

From my reading of the Android documentation and this plugin's source code, exact alarms are being used with RTC_WAKEUP so there shouldn't be much of a delay in the showing of the notification.

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

首先,使用提供的 JavaScript/TypeScript 调度示例,在 Android 13 上复现延迟,并使用 @nativescript/core 8.5.7 和 @nativescript/local-notifications 6.1.1。比较请求的 at 时间与所报告设备上的实际送达时间;完成的标准是识别并修正调度延迟,并验证短间隔和较长间隔下的行为。

由索引模型根据 Issue 内容生成。

评估

技术栈
android, javascript, typescript
领域
mobile-dev
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
需要澄清
新手友好度
28/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。