React-native-background-geolocation: The plugin shouldn't display remote push notifications when app is in foreground

Created on 3 Jun 2018  路  5Comments  路  Source: mauron85/react-native-background-geolocation


Your Environment


  • Plugin version: 0.5.0-alpha.34
  • Platform: iOS
  • OS version: iOS 10
  • Device manufacturer and model: Apple
  • React Native version: 0.55.4
  • Plugin configuration options:
{
  desiredAccuracy: BackgroundGeolocation.HIGH_ACCURACY,
  stationaryRadius: 5,
  distanceFilter: 10,
  debug: false,
  startOnBoot: false,
  startForeground: false,
  stopOnTerminate: true,
  stopOnStillActivity: false
}

Context

When using in conjunction with react-native-push-notification or PushNotificationIOS, react-native-background-geolocation brings notifications in the foreground, and triggers the completion handler.

I don't understand Objective C very well, but it looks like the bug appeared in b29c4462099ce0e2e38f8a04f194e3b95b90d05e: completionHandler is called for iOS 10, for any notification.

If I comment out the lines below, it works as expected.

+ // if (@available(iOS 10, *)) {
+ //     UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
+ //     center.delegate = self;
+ // }

Expected Behavior

Using standard React Native push notifications in iOS, the notification is not expected to be displayed when the app is on the foreground.

Actual Behavior

Remote push notifications are displayed when app is in the foreground.

Possible Fix

When using debug: true, the completionHandler should not be called.
Moreover, the library should not intercept remote push notifications sent from other sources.
Maybe add some metadata to the local notification and call the completion handler only for notifications sent by the plugin itself?

Steps to Reproduce


Context

Debug logs

bug ios

All 5 comments

You've summed it up, pretty nicely.

This "behaviour" was introduced with intention to show show debug messages also when app is in foreground (which was default behaviour in iOS < 10).

As you suggested, some message identification needs to be added, to not display messages that didn't come from the plugin.

Thank you for your response.

As a workaround, I forked the repository and commented out the lines calling the completion handler.
I don't think I can be very helpful on this, I don't speak Objective C 馃槓

This also prevents the push notifications from being sent to the app. As when specifying a delegate for UNUserNotificationCenter, you prevent the default app delegate functions from being called.

It took me hours to understand what broke my notifications...

@danielgindi does your commit 7685972814fe25ca9ccbc4c9777124ccca6f7844 fix the problem?

Yes it does

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mikailbayram picture mikailbayram  路  4Comments

HaswinVidanage picture HaswinVidanage  路  3Comments

anishroff picture anishroff  路  4Comments

MRolandd picture MRolandd  路  6Comments

theebi picture theebi  路  4Comments