forked from rekabhq/background_locator
-
Notifications
You must be signed in to change notification settings - Fork 110
Setup
Valentin Tahon edited this page Jul 12, 2022
·
3 revisions
- Make sure to have the following permissions inside your AndroidManifest.xml:
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
- ACCESS_FINE_LOCATION to have the GPS.
Note: you can set ACCESS_COARSE_LOCATION but you will have to modify the accuracy below
LocationAccuracy.LOW
.
- ACCESS_BACKGROUND_LOCATION To get update in background.
- WAKE_LOCK to not sleep while getting the GPS.
- FOREGROUND_SERVICE To let the plugins operate as a service.
- Add also the following lines to your
AndroidManifest.xml
:
<service android:name="yukams.app.background_locator_2.IsolateHolderService"
android:permission="android.permission.FOREGROUND_SERVICE"
android:exported="true"
android:foregroundServiceType = "location"/>
<meta-data
android:name="flutterEmbedding"
android:value="2" />
- Add the following lines to AppDelegate class:
import background_locator_2
func registerPlugins(registry: FlutterPluginRegistry) -> () {
if (!registry.hasPlugin("BackgroundLocatorPlugin")) {
GeneratedPluginRegistrant.register(with: registry)
}
}
@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
GeneratedPluginRegistrant.register(with: self)
BackgroundLocatorPlugin.setPluginRegistrantCallback(registerPlugins)
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
}
- In app settings enable
Background Modes
and checkLocation Updates
.
- In
Info.plist
add Key for using location service:
NSLocationAlwaysAndWhenInUseUsageDescription
NSLocationWhenInUseUsageDescription