Skip to content
mehdi sohrabi edited this page Jan 20, 2021 · 6 revisions

Setup:

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="rekab.app.background_locator.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

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.

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

Clone this wiki locally