import UIKit import CoreLocation import Flutter @UIApplicationMain @objc class AppDelegate: FlutterAppDelegate, CLLocationManagerDelegate { var locationManager: CLLocationManager? override func application( _ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? ) -> Bool { GeneratedPluginRegistrant.register(with: self) let controller : FlutterViewController = window?.rootViewController as! FlutterViewController let locationServiceChannel = FlutterMethodChannel(name: "location", binaryMessenger: controller.binaryMessenger) /* locationServiceChannel.setMethodCallHandler { (call: FlutterMethodCall, result: @escaping FlutterResult) -> Void in if call.method == "isLocationServiceRunning" { result(self.isLocationServiceRunning()) } else { result(FlutterMethodNotImplemented) } } */ locationServiceChannel.setMethodCallHandler { [weak self] (call: FlutterMethodCall, result: @escaping FlutterResult) -> Void in if call.method == "startLocationService" { //self?.startLocationService() result(nil) } else if call.method == "isLocationServiceRunning" { result(self?.isLocationServiceRunning() ?? false) } else { result(FlutterMethodNotImplemented) } } locationManager = CLLocationManager() locationManager?.delegate = self locationManager?.requestAlwaysAuthorization() locationManager?.startUpdatingLocation() return super.application(application, didFinishLaunchingWithOptions: launchOptions) } private func isLocationServiceRunning() -> Bool { guard let locationManager = locationManager else { return false } let isRunning = locationManager.monitoredRegions.count > 0 || locationManager.location != nil return isRunning } }