NativeScript / plugins

@nativescript plugins to help with your developments.
https://docs.nativescript.org/plugins/index.html
Apache License 2.0
189 stars 107 forks source link

[@nativescript/local-notifications] No notifications are displayed when relying on default option values #595

Open jkatins opened 1 month ago

jkatins commented 1 month ago

Since 6.2.0 (https://github.com/NativeScript/plugins/commit/ed5feb9f85135a3d64a86ef8da5b44f344b1698e in particular) the schedule() function doesn't show any notification if all optional parameters of the scheduleOptions object are omitted. It worked fine with the previous version 6.1.1.

There are two separate problems:

  1. By omitting the at option, its value now defaults to -1 instead of 0: https://github.com/NativeScript/plugins/blob/ed5feb9f85135a3d64a86ef8da5b44f344b1698e/packages/local-notifications/index.android.ts#L207 This causes notifications to never show and there is no error message. The com.telerik.localnotifications package expects 0 for notifications that are supposed to be displayed immediately: https://github.com/EddyVerbruggen/nativescript-local-notifications/blob/master/native-src/android/app/src/main/java/com/telerik/localnotifications/NotificationRestoreReceiver.java#L52 Workaround:
    at: { getTime: () => 0 } as Date
  2. With the above workaround, the first notification is displayed, but any following notification is not and there's this error message: Error in LocalNotifications.schedule: TypeError: iconLocation.indexOf is not a function. This is because the LocalNotificationsCommon.merge() function was rewritten in a way that it modifies one of the objects passed as arguments, as opposed to returning a new object with the merged properties and leaving the argument objects unchanged. Confusingly, the function modifies the source argument instead of the target. This causes the LocalNotificationsImpl.defaults object to be modified here. You can workaround this issue by passing these two options with their default values explicitly:
    icon: "res://ic_stat_notify",   
    silhouetteIcon: "res://ic_stat_notify_silhouette",
insytes commented 1 month ago

My fault, I will pick this up and fix these 2 issues.