Skip to content

Commit

Permalink
Merge pull request #226 from ICTASL/feature/225-remove-location-usage
Browse files Browse the repository at this point in the history
Removed unused location permissions from ios in #225
  • Loading branch information
sachinPramodya authored Dec 23, 2020
2 parents a6952c0 + 964f844 commit 1c36f2d
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 68 deletions.
64 changes: 1 addition & 63 deletions ios/Runner/AppDelegate.swift
Original file line number Diff line number Diff line change
@@ -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, *) {
Expand All @@ -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()
}
}
5 changes: 0 additions & 5 deletions ios/Runner/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,6 @@
<true/>
<key>NSCameraUsageDescription</key>
<string>Myhealth camera permission for qr scanner</string>
<key>UIBackgroundModes</key>
<array>
<string>location</string>
<string>remote-notification</string>
</array>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIMainStoryboardFile</key>
Expand Down

0 comments on commit 1c36f2d

Please sign in to comment.