Cordova-plugin-background-geolocation: plugin doesn't let cordova-plugin-fcm-with-dependecy-updated ^2.4.0 plugin handle notification

Created on 17 Sep 2019  Â·  11Comments  Â·  Source: mauron85/cordova-plugin-background-geolocation

Your Environment


  • Plugin version: 3.0.3
  • Platform: iOS
  • OS version: 11.0.3 and 12.3.1
  • Device manufacturer and model: iPhone 6, iPhone 6s
  • Running in Simulator: no
  • Cordova version (cordova -v): 8.1.2
  • Cordova platform version (cordova platform ls): ios 4.5.4
  • Plugin configuration options:
geolocation.configure({
            locationProvider: _geolocation.ACTIVITY_PROVIDER,
            desiredAccuracy: _geolocation.MEDIUM_ACCURACY,
            stationaryRadius: 0,
            distanceFilter: 0,
            debug: false,
            stopOnTerminate: true,
            stopOnStillActivity: false,
            startForeground: true,
            fastestInterval: 10000,
            interval: 10000,
            maxLocations: 1
        }
  • Link to your project:

Context

in CDVBackgroundGeolocation.m file debugger never goes into if statement

- (void)userNotificationCenter:(UNUserNotificationCenter *)center
       willPresentNotification:(UNNotification *)notification
         withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler
{
    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);
    }
}

Expected Behavior


plugin should let others handle push data (in my case fcm, which works properly without this plugin)

Actual Behavior


debugger always choses else statement and only displays notification in upper banner, no matter if app is foreground

Steps to Reproduce


  1. clear project
  2. cordova plugin add cordova-plugin-fcm-with-dependecy-updated@^2.4.0
  3. cordova plugin add @mauron85/[email protected]
  4. put breakpoint on line 484 in CDVBackgroundGeolocation.m
  5. send any test push from firebase console
stale

Most helpful comment

@nuno @ProximaHaiz @walfridosp @dzziwny @mauron85 I have a PR that fixes the issue https://github.com/mauron85/cordova-plugin-background-geolocation/pull/696

The problem is that it's overriding the notification center delegate. It should only override it when it is in debugging mode. There is no need to comment out the addObserver lines

All 11 comments

I have the same issue.
@dzziwny Do you find a solution?

So, i just removed code, that handle notification and its solved the problem

@ProximaHaiz just in case you haven't fix this issue yet, I solved it from my side by commenting these lines in plugins/cordova-plugin-mauron85-background-geolocation/CDVBackgroundGeolocation.m

    // [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onAppPause:) name:UIApplicationDidEnterBackgroundNotification object:nil];
    // [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onAppResume:) name:UIApplicationWillEnterForegroundNotification object:nil];
    // [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onFinishLaunching:) name:UIApplicationDidFinishLaunchingNotification object:nil];
    // [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onAppTerminate:) name:UIApplicationWillTerminateNotification object:nil];

After that Push Notifications worked as expected.

Hope this helps.

@ProximaHaiz just in case you haven't fix this issue yet, I solved it from my side by commenting these lines in plugins/cordova-plugin-mauron85-background-geolocation/CDVBackgroundGeolocation.m

    // [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onAppPause:) name:UIApplicationDidEnterBackgroundNotification object:nil];
    // [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onAppResume:) name:UIApplicationWillEnterForegroundNotification object:nil];
    // [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onFinishLaunching:) name:UIApplicationDidFinishLaunchingNotification object:nil];
    // [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onAppTerminate:) name:UIApplicationWillTerminateNotification object:nil];

After that Push Notifications worked as expected.

Hope this helps.

Thanks, i commented these lines too)
Also if you are using this plugin or BackgroundMode plugin with sound off, remove audio key from UIBackgroundModes which located in plugin.xml file. Because App Store not allowed to publish my application with that

I have the same problem. I had to comment those lines abone too.
@mauron85 There is a way make the plugin work with all others that suport push notification, like fcm for exemple?
Thanks for you time.

Anyone? @dzziwny @ProximaHaiz @walfridosp @mauron85

@nuno @ProximaHaiz @walfridosp @dzziwny @mauron85 I have a PR that fixes the issue https://github.com/mauron85/cordova-plugin-background-geolocation/pull/696

The problem is that it's overriding the notification center delegate. It should only override it when it is in debugging mode. There is no need to comment out the addObserver lines

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

This issue has been automatically closed, because it has not had recent activity. If you believe this issue shouldn't be closed, please reopen or write down a comment requesting issue reopening with explanation why you think it's important. Thank you for your contributions.

Was this page helpful?
0 / 5 - 0 ratings