Skip to content

Commit

Permalink
iOS avoid taking control of UNUserNotificationCenter
Browse files Browse the repository at this point in the history
Backport from react-native
Origin-PR:
mauron85/react-native-background-geolocation#268
Contributed-By: @danielgindi
  • Loading branch information
mauron85 committed Aug 20, 2018
1 parent 466b21f commit 80be0fd
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion ios/CDVBackgroundGeolocation/CDVBackgroundGeolocation.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ @implementation CDVBackgroundGeolocation {
NSString *callbackId;
MAURConfig *config;
MAURBackgroundGeolocationFacade* facade;

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

- (void)pluginInitialize
Expand Down Expand Up @@ -441,6 +444,18 @@ -(void) onFinishLaunching:(NSNotification *)notification
}

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]) {
NSLog(@"%@ %@", TAG, @"started by system on location event.");
MAURConfig *config = [facade getConfig];
Expand All @@ -455,7 +470,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 80be0fd

Please sign in to comment.