Skip to content
Valentin Tahon edited this page Jul 12, 2022 · 3 revisions

Android

  1. 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.
  1. 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" />

iOS

  1. 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)
  }
}
  1. In app settings enable Background Modes and check Location Updates.

image

  1. In Info.plist add Key for using location service:
NSLocationAlwaysAndWhenInUseUsageDescription
NSLocationWhenInUseUsageDescription

image

Clone this wiki locally