Skip to content

Commit

Permalink
Avoid taking control of UNUserNotificationCenter (#268)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielgindi authored and mauron85 committed Aug 20, 2018
1 parent 0a9b40d commit 7685972
Showing 1 changed file with 26 additions and 7 deletions.
33 changes: 26 additions & 7 deletions ios/RCTBackgroundGeolocation/RCTBackgroundGeolocation.m
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@

@implementation RCTBackgroundGeolocation {
MAURBackgroundGeolocationFacade* facade;

API_AVAILABLE(ios(10.0))
__weak id<UNUserNotificationCenterDelegate> prevNotificationDelegate;
}

@synthesize bridge = _bridge;
Expand Down Expand Up @@ -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];
Expand All @@ -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
Expand Down

0 comments on commit 7685972

Please sign in to comment.