8000 fix(local-notifications): schedule returning list of ids (#612) · NativeScript/plugins@b88da2c · GitHub
[go: up one dir, main page]

Skip to content

Commit b88da2c

Browse files
authored
fix(local-notifications): schedule returning list of ids (#612)
1 parent b42d70c commit b88da2c

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

packages/local-notifications/index.ios.ts

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ export class LocalNotificationsImpl extends LocalNotificationsCommon implements
116116
}
117117
}
118118

119-
private static schedulePendingNotificationsNew(scheduleOptions: ScheduleOptions[]): Array<number> {
119+
private static async schedulePendingNotificationsNew(scheduleOptions: ScheduleOptions[]): Array<number> {
120120
const scheduledIds: number[] = [];
121121

122122
for (const s of scheduleOptions) {
@@ -215,22 +215,24 @@ export class LocalNotificationsImpl extends LocalNotificationsCommon implements
215215
});
216216
}
217217

218-
registerNotification(entry.id, content, trigger, scheduledIds);
218+
scheduledIds.push(await registerNotification(entry.id, content, trigger));
219219

220220
if (interval && entry.displayImmediately) {
221221
const id = LocalNotificationsImpl.generateNotificationID();
222-
registerNotification(id, content, UNTimeIntervalNotificationTrigger.triggerWithTimeIntervalRepeats(2, false), scheduledIds);
222+
scheduledIds.push(await registerNotification(id, content, UNTimeIntervalNotificationTrigger.triggerWithTimeIntervalRepeats(2, false)));
223223
}
224224
}
225225

226-
function registerNotification(id: number, content: UNMutableNotificationContent, trigger: UNNotificationTrigger, register: Array<number>) {
227-
UNUserNotificationCenter.currentNotificationCenter().addNotificationRequestWithCompletionHandler(UNNotificationRequest.requestWithIdentifierContentTrigger('' + id, content, trigger), (error: NSError) => {
228-
if (error) {
229-
console.log(`Error scheduling notification (id ${id}): ${error.localizedDescription}`);
230-
} else {
231-
register.push(id);
232-
console.log(`Notification (id ${id}) scheduled successfully`);
233-
}
226+
function registerNotification(id: number, content: UNMutableNotificationContent, trigger: UNNotificationTrigger) {
227+
return new Promise((resolve) => {
228+
UNUserNotificationCenter.currentNotificationCenter().addNotificationRequestWithCompletionHandler(UNNotificationRequest.requestWithIdentifierContentTrigger('' + id, content, trigger), (error: NSError) => {
229+
if (error) {
230+
console.log(`Error scheduling notification (id ${id}): ${error.localizedDescription}`);
231+
} else {
232+
console.log(`Notification (id ${id}) scheduled successfully`);
233+
}
234+
resolve(id);
235+
});
234236
});
235237
}
236238

@@ -438,18 +440,18 @@ export class LocalNotificationsImpl extends LocalNotificationsCommon implements
438440
}
439441

440442
schedule(scheduleOptions: ScheduleOptions[]): Promise<Array<number>> {
441-
return new Promise((resolve, reject) => {
443+
return new Promise(async (resolve, reject) => {
442444
try {
443445
if (!LocalNotificationsImpl.hasPermission()) {
444-
this.requestPermission().then((granted) => {
446+
this.requestPermission().then(async (granted) => {
445447
if (granted) {
446-
resolve(LocalNotificationsImpl.schedulePendingNotifications(scheduleOptions));
448+
resolve(await LocalNotificationsImpl.schedulePendingNotifications(scheduleOptions));
447449
} else {
448450
reject('Permission not granted');
449451
}
450452
});
451453
} else {
452-
resolve(LocalNotificationsImpl.schedulePendingNotifications(scheduleOptions));
454+
resolve(await LocalNotificationsImpl.schedulePendingNotifications(scheduleOptions));
453455
}
454456
} catch (ex) {
455457
console.log('Error in LocalNotifications.schedule: ' + ex);

0 commit comments

Comments
 (0)
0