Fixed Location Permission issue on Android - 1
This commit is contained in:
@ -8,6 +8,32 @@ import Flutter
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user