Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid taking control of UNUserNotificationCenter (Closes #206, closes #256) #268

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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