NativeScript / NativeScript/plugins

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

Aperta
#529 4 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Lingua principale
TypeScript
Stelle
206
Fork
123
Merge medio
2g 1h
PR unite (30g)
1

Descrizione

  • 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.

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia riproducendo il ritardo su Android 13 con l’esempio di pianificazione JavaScript/TypeScript fornito, usando @nativescript/core 8.5.7 e @nativescript/local-notifications 6.1.1. Confronta l’orario at richiesto con l’orario effettivo di consegna sui dispositivi segnalati; il lavoro è completo quando il ritardo nella pianificazione è stato identificato e corretto e il comportamento è stato verificato per intervalli brevi e più lunghi.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
android, javascript, typescript
Ambito
mobile-dev
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Da chiarire
Idoneità per principianti
28/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.