Files
rog_app/ios/Runner/AppDelegate.swift

55 lines
2.0 KiB
Swift
Raw Normal View History

2022-03-14 12:28:57 +05:30
import UIKit
2024-05-26 11:00:06 +09:00
import CoreLocation
2022-03-14 12:28:57 +05:30
import Flutter
@UIApplicationMain
2024-05-26 11:00:06 +09:00
@objc class AppDelegate: FlutterAppDelegate, CLLocationManagerDelegate {
var locationManager: CLLocationManager?
2022-03-14 12:28:57 +05:30
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)
2024-05-26 11:00:06 +09:00
/*
locationServiceChannel.setMethodCallHandler { (call: FlutterMethodCall, result: @escaping FlutterResult) -> Void in
if call.method == "isLocationServiceRunning" {
result(self.isLocationServiceRunning())
} else {
result(FlutterMethodNotImplemented)
}
}
2024-05-26 11:00:06 +09:00
*/
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()
2022-03-14 12:28:57 +05:30
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
}
2022-03-14 12:28:57 +05:30
}