Skip to content
Open

Dev #593

Show file tree
Hide file tree
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
11 changes: 7 additions & 4 deletions @mauron85_react-native-background-geolocation.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@ Pod::Spec.new do |s|

s.authors = package['author']
s.homepage = package['homepage']
s.platform = :ios, "9.0"
s.platform = :ios, "11.0"

s.source = { :path => "ios" }
s.source_files = "ios/**/*.{h,m}"
s.source = { :git => package['repository']['url'] }
s.source_files = "ios/**/*.{h,m}"
s.exclude_files = "ios/common/BackgroundGeolocationTests/*.{h,m}"

s.dependency 'React'
s.framework = 'CoreLocation'
s.framework = 'CoreMotion'

s.dependency "React-Core"
end
91 changes: 91 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,97 @@ For iOS 11:
6. Add `NSLocationWhenInUseUsageDescription` **App requires background tracking** to `Info.plist`
7. Add `NSLocationAlwaysAndWhenInUseUsageDescription` **App requires background tracking** to `Info.plist`

## Installation avec Expo

### Configuration requise
- Expo SDK 47 ou supérieur
- Un projet Expo configuré avec expo-dev-client

### Installation

1. Installez le package :
```bash
npx expo install @mauron85/react-native-background-geolocation
```

2. Ajoutez les permissions nécessaires dans votre fichier app.json :
```json
{
"expo": {
"plugins": [
[
"expo-location",
{
"locationAlwaysAndWhenInUsePermission": "Autoriser $(PRODUCT_NAME) à utiliser votre localisation en arrière-plan",
"locationAlwaysPermission": "Autoriser $(PRODUCT_NAME) à utiliser votre localisation en arrière-plan",
"locationWhenInUsePermission": "Autoriser $(PRODUCT_NAME) à utiliser votre localisation"
}
]
]
}
}
```


```

### Exemple d'utilisation avec Expo

```javascript
import BackgroundGeolocation from '@mauron85/react-native-background-geolocation';




// Dans votre composant
useEffect(() => {
BackgroundGeolocation.configure({
desiredAccuracy: BackgroundGeolocation.HIGH_ACCURACY,
stationaryRadius: 50,
distanceFilter: 50,
notificationTitle: 'Suivi en arrière-plan',
notificationText: 'activé',
debug: true,
startOnBoot: false,
stopOnTerminate: false,
locationProvider: BackgroundGeolocation.ACTIVITY_PROVIDER,
interval: 10000,
fastestInterval: 5000,
activitiesInterval: 10000,
stopOnStillActivity: false
});

BackgroundGeolocation.on('location', (location) => {
// Gérer la location ici
console.log(location);
});

BackgroundGeolocation.on('error', (error) => {
console.log('[ERROR] BackgroundGeolocation error:', error);
});

BackgroundGeolocation.start();

return () => {
BackgroundGeolocation.removeAllListeners();
};
}, []);
```

### Notes importantes pour Expo

1. Cette intégration nécessite l'utilisation d'expo-dev-client car elle contient du code natif.
2. Pour les builds de production, vous devrez utilquer EAS Build :
```bash
eas build --platform ios
eas build --platform android
```

3. Pour le développement local, utilisez :
```bash
npx expo start --dev-client
```

## API

### configure(options, success, fail)
Expand Down
25 changes: 6 additions & 19 deletions android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,40 +1,27 @@

buildscript {
repositories {
maven {
url 'https://maven.google.com/'
name 'Google'
}
jcenter()
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.1'
classpath 'com.android.tools.build:gradle:7.3.1'
}
}

allprojects {
repositories {
mavenLocal()
google()
mavenCentral()
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url "$rootDir/../node_modules/react-native/android"
}
maven {
url 'https://maven.google.com/'
name 'Google'
}
jcenter()
// repo for react-native
// https://mvnrepository.com/artifact/com.facebook.react/react-native?repo=springio-plugins-release
maven {
url 'http://repo.spring.io/plugins-release/'
name 'Spring Plugins'
}
}
}

ext {
reactNativeLibVersion = "0.55.3"
reactNativeLibVersion = "0.71.0"
}

task clean(type: Delete) {
Expand Down
2 changes: 1 addition & 1 deletion android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
42 changes: 10 additions & 32 deletions android/lib/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,50 +29,28 @@ apply plugin: 'com.android.library'
apply from: '../common/VERSIONS.gradle'
def hasApp = findProject(':app') != null

// https://hackernoon.com/android-how-to-add-gradle-dependencies-using-foreach-c4cbcc070458
def projDependencies = [
[configuration: "implementation", dependency: libs.slf4j],
[configuration: "implementation", dependency: libs.reactNative],
[configuration: "testImplementation", dependency: testLibs.testRunner],
[configuration: "testImplementation", dependency: testLibs.testRules],
[configuration: "testImplementation", dependency: testLibs.junit],
[configuration: "testImplementation", dependency: testLibs.powermockMockito],
[configuration: "testImplementation", dependency: testLibs.powermockjUnit],
[configuration: "testImplementation", dependency: testLibs.powermockClassloading],
[configuration: "testImplementation", dependency: testLibs.mockitoCore],
[configuration: "testImplementation", dependency: testLibs.festAssertCore],
[configuration: "testImplementation", dependency: testLibs.robolectric],
[configuration: "androidTestImplementation", dependency: testLibs.testRunner],
[configuration: "androidTestImplementation", dependency: testLibs.testRules],
[configuration: "androidTestImplementation", dependency: "androidx.test:runner:1.5.2"],
[configuration: "androidTestImplementation", dependency: "androidx.test:rules:1.5.0"],
]

repositories {
// Google dependencies are now hosted at Maven
// unfortunately this is ignored when installing as react-native plugin
maven {
url 'https://maven.google.com'
}
jcenter()
google()
mavenCentral()
}

android {
compileSdkVersion project.ext.getCompileSdkVersion()
buildToolsVersion project.ext.getBuildToolsVersion()
if (hasApp) {
evaluationDependsOn(':app')
}

// Tip: https://stackoverflow.com/questions/39987669/renamingdelegatingcontext-is-deprecated-how-do-we-test-sqlite-db-now/52170737#52170737
// Gradle automatically adds 'android.test.runner' as a dependency.
useLibrary 'android.test.runner'
useLibrary 'android.test.base'
useLibrary 'android.test.mock'

compileSdkVersion 33

defaultConfig {
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
minSdkVersion project.ext.getMinSdkVersion()
targetSdkVersion project.ext.getTargetSdkVersion()
versionCode 1 // intentionally not updating version as we're not uploading to any java repository
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
minSdkVersion 21
targetSdkVersion 33
versionCode 1
versionName "1.0"
}

Expand Down
Loading