@@ -116,7 +116,7 @@ export class LocalNotificationsImpl extends LocalNotificationsCommon implements
116
116
}
117
117
}
118
118
119
- private static schedulePendingNotificationsNew ( scheduleOptions : ScheduleOptions [ ] ) : Array < number > {
119
+ private static async schedulePendingNotificationsNew ( scheduleOptions : ScheduleOptions [ ] ) : Array < number > {
120
120
const scheduledIds : number [ ] = [ ] ;
121
121
122
122
for ( const s of scheduleOptions ) {
@@ -215,22 +215,24 @@ export class LocalNotificationsImpl extends LocalNotificationsCommon implements
215
215
} ) ;
216
216
}
217
217
218
- registerNotification ( entry . id , content , trigger , scheduledIds ) ;
218
+ scheduledIds . push ( await registerNotification ( entry . id , content , trigger ) ) ;
219
219
220
220
if ( interval && entry . displayImmediately ) {
221
221
const id = LocalNotificationsImpl . generateNotificationID ( ) ;
222
- registerNotification ( id , content , UNTimeIntervalNotificationTrigger . triggerWithTimeIntervalRepeats ( 2 , false ) , scheduledIds ) ;
222
+ scheduledIds . push ( await registerNotification ( id , content , UNTimeIntervalNotificationTrigger . triggerWithTimeIntervalRepeats ( 2 , false ) ) ) ;
223
223
}
224
224
}
225
225
226
- function registerNotification ( id : number , content : UNMutableNotificationContent , trigger : UNNotificationTrigger , register : Array < number > ) {
227
10000
code>
- 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
+ } ) ;
234
236
} ) ;
235
237
}
236
238
@@ -438,18 +440,18 @@ export class LocalNotificationsImpl extends LocalNotificationsCommon implements
438
440
}
439
441
440
442
schedule ( scheduleOptions : ScheduleOptions [ ] ) : Promise < Array < number > > {
441
- return new Promise ( ( resolve , reject ) => {
443
+ return new Promise ( async ( resolve , reject ) => {
442
444
try {
443
445
if ( ! LocalNotificationsImpl . hasPermission ( ) ) {
444
- this . requestPermission ( ) . then ( ( granted ) => {
446
+ this . requestPermission ( ) . then ( async ( granted ) => {
445
447
if ( granted ) {
446
- resolve ( LocalNotificationsImpl . schedulePendingNotifications ( scheduleOptions ) ) ;
448
+ resolve ( await LocalNotificationsImpl . schedulePendingNotifications ( scheduleOptions ) ) ;
447
449
} else {
448
450
reject ( 'Permission not granted' ) ;
449
451
}
450
452
} ) ;
451
453
} else {
452
- resolve ( LocalNotificationsImpl . schedulePendingNotifications ( scheduleOptions ) ) ;
454
+ resolve ( await LocalNotificationsImpl . schedulePendingNotifications ( scheduleOptions ) ) ;
453
455
}
454
456
} catch ( ex ) {
455
457
console . log ( 'Error in LocalNotifications.schedule: ' + ex ) ;
0 commit comments