From f2aeec6fd2f793cdec0728155db91866783cb039 Mon Sep 17 00:00:00 2001 From: Selim Mustafaev Date: Thu, 17 Sep 2020 22:05:57 +0300 Subject: [PATCH] Requesting full location access --- AutoCat/Controllers/SearchController.swift | 11 +++++++++++ AutoCat/Info.plist | 6 ++++-- AutoCat/Utils/Location.swift | 2 +- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/AutoCat/Controllers/SearchController.swift b/AutoCat/Controllers/SearchController.swift index 8b7f49c..c760332 100644 --- a/AutoCat/Controllers/SearchController.swift +++ b/AutoCat/Controllers/SearchController.swift @@ -10,6 +10,7 @@ class SearchController: UIViewController, UISearchResultsUpdating { let bag = DisposeBag() let searchController = UISearchController(searchResultsController: nil) + var refreshControl = UIRefreshControl() var filterRelay = BehaviorRelay(value: Filter()) var filter = Filter() @@ -24,6 +25,10 @@ class SearchController: UIViewController, UISearchResultsUpdating { searchController.searchBar.placeholder = "Search plate numbers" navigationItem.searchController = searchController definesPresentationContext = true + + //self.refreshControl.attributedTitle = NSAttributedString(string: "") + self.refreshControl.addTarget(self, action: #selector(self.refresh(_:)), for: .valueChanged) + self.tableView.addSubview(self.refreshControl) let ds = RxTableViewSectionedAnimatedDataSource>(configureCell: { dataSource, tableView, indexPath, item in if let cell = tableView.dequeueReusableCell(withIdentifier: "VehicleCell", for: indexPath) as? VehicleCell { @@ -51,6 +56,7 @@ class SearchController: UIViewController, UISearchResultsUpdating { .do(onNext: { self.navigationItem.title = "\($0.count) vehicles found" self.showMapButton.isEnabled = $0.count > 0 + self.refreshControl.endRefreshing() }) .map { $0.groupedByDate() } .bind(to: self.tableView.rx.items(dataSource: ds)) @@ -114,4 +120,9 @@ class SearchController: UIViewController, UISearchResultsUpdating { //self.navigationController?.pushViewController(controller, animated: true) self.present(controller, animated: true) } + + @objc func refresh(_ sender: AnyObject) { + self.showMapButton.isEnabled = false + self.filterRelay.accept(self.filter) + } } diff --git a/AutoCat/Info.plist b/AutoCat/Info.plist index 849fb36..1ae5983 100644 --- a/AutoCat/Info.plist +++ b/AutoCat/Info.plist @@ -2,6 +2,8 @@ + NSLocationWhenInUseUsageDescription + Access is needed for storing locations of vehicles CFBundleDevelopmentRegion $(DEVELOPMENT_LANGUAGE) CFBundleExecutable @@ -42,8 +44,8 @@ - NSLocationWhenInUseUsageDescription - Access is needed for storing locations of vehicles + NSLocationAlwaysAndWhenInUseUsageDescription + Access is needed for storing locations of vehicles (even when the app was sent to bacground) NSMicrophoneUsageDescription Access is needed for voice recordings NSPhotoLibraryAddUsageDescription diff --git a/AutoCat/Utils/Location.swift b/AutoCat/Utils/Location.swift index 9684b1c..063eec0 100644 --- a/AutoCat/Utils/Location.swift +++ b/AutoCat/Utils/Location.swift @@ -76,7 +76,7 @@ class LocationManager { observer(.success(())) break case .notDetermined: - self.manager.requestWhenInUseAuthorization() + self.manager.requestAlwaysAuthorization() let proxy = RxLocationManagerDelegateProxy.proxy(for: self.manager) _ = proxy.authSubject.filter{ $0 != .notDetermined }.first().subscribe(onSuccess: { result in if let status = result, [.authorizedWhenInUse, .authorizedAlways].contains(status) {