[New Features] Promise API, Two new events, new Initialization method #ready #441
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a rather large refactor of the iOS / Android configuration API, in addition to some other native API, making them less "json-centric" with more traditional Obj-c / Android APIs.
This version will be called
2.12.0
, available now in master (not yet tagged).Android Installation Change
The Android plugin makes a slight change to the installation procedure. Gone is
flatDirs
, replaced with a localmaven url
:π
android/build.gradle
Also note the installation procedure now includes directions for setting up
react-native-background-fetch
, which now supports Android.See the Installation docs for more information:
Android react-native link setup
Android Manual setup
Android Application-wide Configuration Parameters
In order to assist with solving gradle dependency version-conflicts (eg:
play-services
,firebase
), the plugin is now aware of several key gradle configuration parameters and will use them when detected. In your rootbuild.gradle
file, if you provide the following parameters, the plugin will align itself to them:π
android/build.gradle
In your application's "root" gradle file, define global properties to be used by your app and all the modules you include into it:
See Wiki Solving Android Gradle Conflicts for more information.
New Initialization method:
#ready
This PR deprecates the
#configure
method in favour of a new initialization method named#ready
. Since the plugin has always persisted the supplied configuration, it's always bugged me having to re-apply the{config}
object every time the app launches. With#ready
, the plugin will detect the first launch of your application and only apply the supplied{config}
object then β each launch thereafter, the plugin will automatically apply the last known configuration from persistent storage.Observe the following example. Imagine you've deleted the app from the device and re-installed it:
In the console, you'll see
Somewhere else in your code, you change the
distanceFilter
:Now terminate the app and reboot. In the console, you'll see:
The
#ready
method will apply the supplied{config}
ONLY at first launch of your application. Thereafter, it will load the last known configuration from persistent storage.New method:
#reset
The plugin now includes a method
#reset
to reset the plugin to documented defaults. For more information, see the docs for#reset
.reset: true
Optionally, you can specify
reset: true
to#ready
. This will esentially force the supplied{config}
to be applied with each launch of your application, making it behave like the traditional#configure
method.Javascript API Now uses Promises
BackgroundGeolocation
Javascript API supports Promises for nearly every method (the exceptions are#watchPosition
and adding event-listeners via#on
method.Using
await
By marking one of your application methods as
async
you can use theawait
mechanism instead of callbacks:Two New Events:
connectivitychange
,enabledchange
connectivitychange
Fired when the state of the device's network-connectivity changes (enabled -> disabled and vice-versa). By default, the plugin will automatically fire a
connectivitychange
event with the current state network-connectivity whenever the#start
method is executed.enabledchange
Fired when the plugin's
enabled
state changes. For example, executing#start
and#stop
will cause theenabledchange
event to fire. This event is primarily desigend for use with the configuration option [stopAfterElapsedMinutes
], which automatically executes the plugin's#stop
method.#ready
, desigend to replace#configure
(which is now deprectated). The new#ready
method operates in the same manner as#configure
with a crucial difference -- the plugin will only apply the supplied configuration{}
at the first launch of your app β thereafter, it will automatically load the last-known config from persistent storage.#reset
for resetting the plugin configuration to documented defaults.#watchPosition
and adding event-listeners with#on
will not use promises.#stop
method is executed while stop-detection system is engaged.providerchange
event after the result of user location-authorization (accept/deny). The result will be available in thestatus
key of the event-object.#getCurrentPosition
,#watchPosition
) and geofencing.connectivitychange
for detecting network connectivity state-changes.enabledchange
, fired with the plugin enabled state changes. Executing#start
/#stop
will cause this event to fire. This is primarily designed for use withstopAfterElapsedMinutes
.