@@ -297,8 +297,9 @@ - (void)scheduleLocalNotification:(iOSNotificationData*)data
297
297
if (data->threadIdentifier != NULL )
298
298
content.threadIdentifier = [NSString stringWithUTF8String: data->threadIdentifier];
299
299
300
- // TODO add a way to specify custom sounds.
301
- content.sound = [UNNotificationSound defaultSound ];
300
+ UNNotificationSound * sound = [self soundForNotification: data];
301
+ if (sound != nil )
302
+ content.sound = sound;
302
303
303
304
content.attachments = (__bridge_transfer NSArray <UNNotificationAttachment *>*)data->attachments ;
304
305
data->attachments = NULL ;
@@ -363,5 +364,47 @@ - (void)scheduleLocalNotification:(iOSNotificationData*)data
363
364
}];
364
365
}
365
366
367
+ - (UNNotificationSound *)soundForNotification : (const iOSNotificationData*)data
368
+ {
369
+ NSString * soundName = nil ;
370
+ if (data->soundName != NULL )
371
+ soundName = [NSString stringWithUTF8String: data->soundName];
372
+
373
+ switch (data->soundType )
374
+ {
375
+ case kSoundTypeNone :
376
+ return nil ;
377
+ case kSoundTypeCritical :
378
+ if (@available (iOS 12.0 , *))
379
+ {
380
+ if (soundName != nil )
381
+ {
382
+ if (data->soundVolume < 0 )
383
+ return [UNNotificationSound criticalSoundNamed: soundName withAudioVolume: data->soundVolume];
384
+ return [UNNotificationSound criticalSoundNamed: soundName];
385
+ }
386
+ if (data->soundVolume >= 0 )
387
+ return [UNNotificationSound defaultCriticalSoundWithAudioVolume: data->soundVolume];
388
+ return UNNotificationSound .defaultCriticalSound ;
389
+ }
390
+ else
391
+ goto default_fallback;
392
+ case kSoundTypeRingtone :
393
+ if (@available (iOS 15.2 , *))
394
+ {
395
+ if (soundName != nil )
396
+ return [UNNotificationSound ringtoneSoundNamed: soundName];
397
+ return UNNotificationSound .defaultRingtoneSound ;
398
+ }
399
+ // continue to default
400
+ case kSoundTypeDefault :
401
+ default :
402
+ default_fallback:
403
+ if (soundName != nil )
404
+ return [UNNotificationSound soundNamed: soundName];
405
+ return UNNotificationSound .defaultSound ;
406
+ }
407
+ }
408
+
366
409
@end
367
410
#endif
0 commit comments