From ec0d909456bf8184ed01318258948bad039f315d Mon Sep 17 00:00:00 2001 From: Joseph Pender Date: Thu, 14 Jan 2021 16:17:24 -0600 Subject: [PATCH 1/7] Allow specification of a number or string for notification id --- local-notifications/src/definitions.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/local-notifications/src/definitions.ts b/local-notifications/src/definitions.ts index 606a488ce..3158ea0a2 100644 --- a/local-notifications/src/definitions.ts +++ b/local-notifications/src/definitions.ts @@ -162,7 +162,7 @@ export interface LocalNotificationDescriptor { * * @since 1.0.0 */ - id: string; + id: number | string; } export interface ScheduleOptions { @@ -462,7 +462,7 @@ export interface LocalNotificationSchema { * * @since 1.0.0 */ - id: number; + id: number | string; /** * Schedule this notification for a later time. From cdcd0928dd492d85c2511d28aff3964774280210 Mon Sep 17 00:00:00 2001 From: Joseph Pender Date: Tue, 19 Jan 2021 10:48:29 -0600 Subject: [PATCH 2/7] Allow integers and string as input for canceling local notifications --- .../ios/Plugin/LocalNotificationsPlugin.swift | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/local-notifications/ios/Plugin/LocalNotificationsPlugin.swift b/local-notifications/ios/Plugin/LocalNotificationsPlugin.swift index 588ae3e14..f3c6c4886 100644 --- a/local-notifications/ios/Plugin/LocalNotificationsPlugin.swift +++ b/local-notifications/ios/Plugin/LocalNotificationsPlugin.swift @@ -137,7 +137,14 @@ public class LocalNotificationsPlugin: CAPPlugin { return } - let ids = notifications.map { $0["id"] as? String ?? "" } + let ids = notifications.map({ (value: JSObject) -> String in + if let idString = value["id"] as? String { + return idString + } else if let idNum = value["id"] as? NSNumber { + return idNum.stringValue + } + return "" + }) UNUserNotificationCenter.current().removePendingNotificationRequests(withIdentifiers: ids) call.resolve() From c11aee5bff09ef2b928e8cfd8fd2be23dc739ed2 Mon Sep 17 00:00:00 2001 From: Joseph Pender Date: Tue, 19 Jan 2021 12:40:51 -0600 Subject: [PATCH 3/7] accept string as notification id input --- .../ios/Plugin/LocalNotificationsPlugin.swift | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/local-notifications/ios/Plugin/LocalNotificationsPlugin.swift b/local-notifications/ios/Plugin/LocalNotificationsPlugin.swift index f3c6c4886..24a702eab 100644 --- a/local-notifications/ios/Plugin/LocalNotificationsPlugin.swift +++ b/local-notifications/ios/Plugin/LocalNotificationsPlugin.swift @@ -43,7 +43,15 @@ public class LocalNotificationsPlugin: CAPPlugin { var ids = [String]() for notification in notifications { - guard let identifier = notification["id"] as? Int else { + var identifierValue = notification["id"] as? Int + + if identifierValue == nil { + if let identifierString = notification["id"] as? String { + identifierValue = Int(identifierString) + } + } + + guard let identifier = identifierValue else { call.reject("Notification missing identifier") return } From c7be98e94b1c6cf13023cf38177ee98d1d8b9800 Mon Sep 17 00:00:00 2001 From: Joseph Pender Date: Mon, 25 Jan 2021 10:32:39 -0600 Subject: [PATCH 4/7] Changing notification id to be integer only --- local-notifications/src/definitions.ts | 4 ++-- local-notifications/src/web.ts | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/local-notifications/src/definitions.ts b/local-notifications/src/definitions.ts index 3158ea0a2..2cb1d5707 100644 --- a/local-notifications/src/definitions.ts +++ b/local-notifications/src/definitions.ts @@ -162,7 +162,7 @@ export interface LocalNotificationDescriptor { * * @since 1.0.0 */ - id: number | string; + id: number; } export interface ScheduleOptions { @@ -462,7 +462,7 @@ export interface LocalNotificationSchema { * * @since 1.0.0 */ - id: number | string; + id: number; /** * Schedule this notification for a later time. diff --git a/local-notifications/src/web.ts b/local-notifications/src/web.ts index 0faebafca..5ba667cb2 100644 --- a/local-notifications/src/web.ts +++ b/local-notifications/src/web.ts @@ -35,7 +35,7 @@ export class LocalNotificationsWeb return { notifications: options.notifications.map(notification => ({ - id: notification.id.toString(), + id: notification.id, })), }; } @@ -43,7 +43,7 @@ export class LocalNotificationsWeb async getPending(): Promise { return { notifications: this.pending.map(notification => ({ - id: notification.id.toString(), + id: notification.id, })), }; } @@ -55,7 +55,7 @@ export class LocalNotificationsWeb async cancel(pending: ScheduleResult): Promise { this.pending = this.pending.filter( notification => - !pending.notifications.find(n => n.id === notification.id.toString()), + !pending.notifications.find(n => n.id === notification.id), ); } From 1f5291abcd6f5934167bf217ca3881db32fa8c28 Mon Sep 17 00:00:00 2001 From: Joseph Pender Date: Mon, 25 Jan 2021 10:59:50 -0600 Subject: [PATCH 5/7] [iOS] accepting / returning integer ids for notifications --- .../ios/Plugin/LocalNotificationsPlugin.swift | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/local-notifications/ios/Plugin/LocalNotificationsPlugin.swift b/local-notifications/ios/Plugin/LocalNotificationsPlugin.swift index 24a702eab..83062ec25 100644 --- a/local-notifications/ios/Plugin/LocalNotificationsPlugin.swift +++ b/local-notifications/ios/Plugin/LocalNotificationsPlugin.swift @@ -43,15 +43,7 @@ public class LocalNotificationsPlugin: CAPPlugin { var ids = [String]() for notification in notifications { - var identifierValue = notification["id"] as? Int - - if identifierValue == nil { - if let identifierString = notification["id"] as? String { - identifierValue = Int(identifierString) - } - } - - guard let identifier = identifierValue else { + guard let identifier = notification["id"] as? Int else { call.reject("Notification missing identifier") return } @@ -549,7 +541,7 @@ public class LocalNotificationsPlugin: CAPPlugin { func makePendingNotificationRequestJSObject(_ request: UNNotificationRequest) -> JSObject { return [ - "id": request.identifier + "id": Int(request.identifier) ?? -1 ] } From 701e3bc7ba3202531e5421440f5720a4bf4f7352 Mon Sep 17 00:00:00 2001 From: Joseph Pender Date: Mon, 25 Jan 2021 11:01:34 -0600 Subject: [PATCH 6/7] [android] accepting / returning integer ids for notifications --- .../plugins/localnotifications/LocalNotification.java | 7 ++++++- .../localnotifications/LocalNotificationsPlugin.java | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/local-notifications/android/src/main/java/com/capacitorjs/plugins/localnotifications/LocalNotification.java b/local-notifications/android/src/main/java/com/capacitorjs/plugins/localnotifications/LocalNotification.java index 5582392d7..fe28faa69 100644 --- a/local-notifications/android/src/main/java/com/capacitorjs/plugins/localnotifications/LocalNotification.java +++ b/local-notifications/android/src/main/java/com/capacitorjs/plugins/localnotifications/LocalNotification.java @@ -252,7 +252,12 @@ public static JSObject buildLocalNotificationPendingList(List ids) { JSArray jsArray = new JSArray(); for (String id : ids) { JSObject notification = new JSObject(); - notification.put("id", id); + try { + int intId = Integer.parseInt(id); + notification.put("id", intId); + } catch (NumberFormatException ex) { + notification.put("id", -1); + } jsArray.put(notification); } result.put("notifications", jsArray); diff --git a/local-notifications/android/src/main/java/com/capacitorjs/plugins/localnotifications/LocalNotificationsPlugin.java b/local-notifications/android/src/main/java/com/capacitorjs/plugins/localnotifications/LocalNotificationsPlugin.java index 2983c99bc..5c284e4f8 100644 --- a/local-notifications/android/src/main/java/com/capacitorjs/plugins/localnotifications/LocalNotificationsPlugin.java +++ b/local-notifications/android/src/main/java/com/capacitorjs/plugins/localnotifications/LocalNotificationsPlugin.java @@ -63,7 +63,7 @@ public void schedule(PluginCall call) { JSArray jsArray = new JSArray(); for (int i = 0; i < ids.length(); i++) { try { - JSObject notification = new JSObject().put("id", ids.getString(i)); + JSObject notification = new JSObject().put("id", ids.getInt(i)); jsArray.put(notification); } catch (Exception ex) {} } From ee9b01bc89c12cff79e5a2e9c6dc7d7d60c8d2b6 Mon Sep 17 00:00:00 2001 From: jcesarmobile Date: Thu, 28 Jan 2021 16:47:46 +0100 Subject: [PATCH 7/7] add missing ints (#214) --- local-notifications/README.md | 2 +- local-notifications/ios/Plugin/LocalNotificationsHandler.swift | 2 +- local-notifications/ios/Plugin/LocalNotificationsPlugin.swift | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/local-notifications/README.md b/local-notifications/README.md index b9256806c..d22dd51ce 100644 --- a/local-notifications/README.md +++ b/local-notifications/README.md @@ -273,7 +273,7 @@ The object that describes a local notification. | Prop | Type | Description | Since | | -------- | ------------------- | ---------------------------- | ----- | -| **`id`** | string | The notification identifier. | 1.0.0 | +| **`id`** | number | The notification identifier. | 1.0.0 | #### ScheduleOptions diff --git a/local-notifications/ios/Plugin/LocalNotificationsHandler.swift b/local-notifications/ios/Plugin/LocalNotificationsHandler.swift index 427a5d5bf..a8a4b95d7 100644 --- a/local-notifications/ios/Plugin/LocalNotificationsHandler.swift +++ b/local-notifications/ios/Plugin/LocalNotificationsHandler.swift @@ -75,7 +75,7 @@ public class LocalNotificationsHandler: NSObject, NotificationHandlerProtocol { func makeNotificationRequestJSObject(_ request: UNNotificationRequest) -> JSObject { let notificationRequest = notificationRequestLookup[request.identifier] ?? [:] return [ - "id": request.identifier, + "id": Int(request.identifier) ?? -1, "title": request.content.title, "sound": notificationRequest["sound"] ?? "", "body": request.content.body, diff --git a/local-notifications/ios/Plugin/LocalNotificationsPlugin.swift b/local-notifications/ios/Plugin/LocalNotificationsPlugin.swift index 83062ec25..1ee6e437b 100644 --- a/local-notifications/ios/Plugin/LocalNotificationsPlugin.swift +++ b/local-notifications/ios/Plugin/LocalNotificationsPlugin.swift @@ -88,7 +88,7 @@ public class LocalNotificationsPlugin: CAPPlugin { let ret = ids.map({ (id) -> JSObject in return [ - "id": id + "id": Int(id) ?? -1 ] }) call.resolve([