Skip to content

Commit 6df9a81

Browse files
committed
Avoid taking control of UNUserNotificationCenter
1 parent 0a9b40d commit 6df9a81

File tree

1 file changed

+26
-7
lines changed

1 file changed

+26
-7
lines changed

ios/RCTBackgroundGeolocation/RCTBackgroundGeolocation.m

100644100755
+26-7
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525

2626
@implementation RCTBackgroundGeolocation {
2727
MAURBackgroundGeolocationFacade* facade;
28+
29+
API_AVAILABLE(ios(10.0))
30+
__weak id<UNUserNotificationCenterDelegate> prevNotificationDelegate;
2831
}
2932

3033
@synthesize bridge = _bridge;
@@ -375,16 +378,21 @@ -(void) onAppPause:(NSNotification *)notification
375378
*/
376379
-(void) onFinishLaunching:(NSNotification *)notification
377380
{
378-
if (@available(iOS 10, *)) {
379-
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
380-
center.delegate = self;
381-
}
382-
383381
NSDictionary *dict = [notification userInfo];
384382

383+
MAURConfig *config = [facade getConfig];
384+
if (config.isDebugging)
385+
{
386+
if (@available(iOS 10, *))
387+
{
388+
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
389+
prevNotificationDelegate = center.delegate;
390+
center.delegate = self;
391+
}
392+
}
393+
385394
if ([dict objectForKey:UIApplicationLaunchOptionsLocationKey]) {
386395
RCTLogInfo(@"RCTBackgroundGeolocation started by system on location event.");
387-
MAURConfig *config = [facade getConfig];
388396
if (![config stopOnTerminate]) {
389397
[facade start:nil];
390398
[facade switchMode:MAURBackgroundMode];
@@ -396,7 +404,18 @@ -(void) userNotificationCenter:(UNUserNotificationCenter *)center
396404
willPresentNotification:(UNNotification *)notification
397405
withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler
398406
{
399-
completionHandler(UNNotificationPresentationOptionAlert);
407+
if (prevNotificationDelegate && [prevNotificationDelegate respondsToSelector:@selector(userNotificationCenter:willPresentNotification:withCompletionHandler:)])
408+
{
409+
// Give other delegates (like FCM) the chance to process this notification
410+
411+
[prevNotificationDelegate userNotificationCenter:center willPresentNotification:notification withCompletionHandler:^(UNNotificationPresentationOptions options) {
412+
completionHandler(UNNotificationPresentationOptionAlert);
413+
}];
414+
}
415+
else
416+
{
417+
completionHandler(UNNotificationPresentationOptionAlert);
418+
}
400419
}
401420

402421
-(void) onAppTerminate:(NSNotification *)notification

0 commit comments

Comments
 (0)