From 964f844f4525014a8f675973779f796efd720038 Mon Sep 17 00:00:00 2001 From: Pavan Welihinda Date: Wed, 23 Dec 2020 10:53:02 +0530 Subject: [PATCH] Removed unused location permissions from ios in #225 --- ios/Runner/AppDelegate.swift | 64 +----------------------------------- ios/Runner/Info.plist | 5 --- 2 files changed, 1 insertion(+), 68 deletions(-) diff --git a/ios/Runner/AppDelegate.swift b/ios/Runner/AppDelegate.swift index 5d0becc..9014614 100644 --- a/ios/Runner/AppDelegate.swift +++ b/ios/Runner/AppDelegate.swift @@ -1,51 +1,13 @@ import UIKit import Flutter -import CoreLocation @UIApplicationMain -@objc class AppDelegate: FlutterAppDelegate, CLLocationManagerDelegate { - let locationManager = CLLocationManager() - - var isSupportingLocationUpdates = false +@objc class AppDelegate: FlutterAppDelegate { override func application( _ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? ) -> Bool { - isSupportingLocationUpdates = CLLocationManager.significantLocationChangeMonitoringAvailable() - if (isSupportingLocationUpdates) { - locationManager.requestAlwaysAuthorization() - if #available(iOS 9.0, *) { - locationManager.allowsBackgroundLocationUpdates = true - } - locationManager.delegate = self - startLocationUpdate() - } - - let controller = window?.rootViewController as! FlutterViewController - let locationChannel = FlutterMethodChannel(name: "location", binaryMessenger: controller.binaryMessenger) - - locationChannel.setMethodCallHandler({ - [weak self] (call: FlutterMethodCall, result: FlutterResult) -> Void in - // Note: this method is invoked on the UI thread. - - if !(self?.isSupportingLocationUpdates ?? false) { - result(FlutterError(code: "Unavailable", - message: "Location is not available", - details: nil)) - return - } - - if call.method == "getLocation" { - result(self?.getLocation()) - } else if call.method == "startLocationUpdates" { - self?.startLocationUpdate() - } else if call.method == "stopLocationUpdates" { - self?.stopLocationUpdate() - } else { - result(FlutterMethodNotImplemented) - } - }) // Messaging if #available(iOS 10.0, *) { @@ -55,28 +17,4 @@ import CoreLocation GeneratedPluginRegistrant.register(with: self) return super.application(application, didFinishLaunchingWithOptions: launchOptions) } - - func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) { - locations.forEach { (location) in - LocationsStorage.shared.saveLocationOnDisk(location: Location(location.coordinate, date: location.timestamp)) - } - } - - private func getLocation() -> [String] { - let encoder = JSONEncoder() - return LocationsStorage.shared.locations.map { (location) -> String in - guard let data = try? encoder.encode(location) else { - return "" - } - return String(data: data, encoding: .utf8)! - } - } - - private func startLocationUpdate() { - locationManager.startMonitoringSignificantLocationChanges() - } - - private func stopLocationUpdate() { - locationManager.stopMonitoringSignificantLocationChanges() - } } diff --git a/ios/Runner/Info.plist b/ios/Runner/Info.plist index 7dcbb79..d2e0adb 100644 --- a/ios/Runner/Info.plist +++ b/ios/Runner/Info.plist @@ -26,11 +26,6 @@ NSCameraUsageDescription Myhealth camera permission for qr scanner - UIBackgroundModes - - location - remote-notification - UILaunchStoryboardName LaunchScreen UIMainStoryboardFile