Fixed Location Permission issue on Android - 1

This commit is contained in:
2024-05-24 07:21:28 +09:00
parent 74f6a79a36
commit e55674e1b9
19 changed files with 376 additions and 330 deletions

View File

@ -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
}
}