diff --git a/ios/RCTBackgroundGeolocation/RCTBackgroundGeolocation.m b/ios/RCTBackgroundGeolocation/RCTBackgroundGeolocation.m old mode 100644 new mode 100755 index b37b7f41..43578c48 --- a/ios/RCTBackgroundGeolocation/RCTBackgroundGeolocation.m +++ b/ios/RCTBackgroundGeolocation/RCTBackgroundGeolocation.m @@ -25,6 +25,9 @@ @implementation RCTBackgroundGeolocation { MAURBackgroundGeolocationFacade* facade; + + API_AVAILABLE(ios(10.0)) + __weak id prevNotificationDelegate; } @synthesize bridge = _bridge; @@ -375,16 +378,21 @@ -(void) onAppPause:(NSNotification *)notification */ -(void) onFinishLaunching:(NSNotification *)notification { - if (@available(iOS 10, *)) { - UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter]; - center.delegate = self; - } - NSDictionary *dict = [notification userInfo]; + MAURConfig *config = [facade getConfig]; + if (config.isDebugging) + { + if (@available(iOS 10, *)) + { + UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter]; + prevNotificationDelegate = center.delegate; + center.delegate = self; + } + } + if ([dict objectForKey:UIApplicationLaunchOptionsLocationKey]) { RCTLogInfo(@"RCTBackgroundGeolocation started by system on location event."); - MAURConfig *config = [facade getConfig]; if (![config stopOnTerminate]) { [facade start:nil]; [facade switchMode:MAURBackgroundMode]; @@ -396,7 +404,18 @@ -(void) userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler { - completionHandler(UNNotificationPresentationOptionAlert); + if (prevNotificationDelegate && [prevNotificationDelegate respondsToSelector:@selector(userNotificationCenter:willPresentNotification:withCompletionHandler:)]) + { + // Give other delegates (like FCM) the chance to process this notification + + [prevNotificationDelegate userNotificationCenter:center willPresentNotification:notification withCompletionHandler:^(UNNotificationPresentationOptions options) { + completionHandler(UNNotificationPresentationOptionAlert); + }]; + } + else + { + completionHandler(UNNotificationPresentationOptionAlert); + } } -(void) onAppTerminate:(NSNotification *)notification