Requesting location authorization
This commit is contained in:
parent
c5e5a343d3
commit
03c1b08f63
@ -7,6 +7,7 @@
|
|||||||
objects = {
|
objects = {
|
||||||
|
|
||||||
/* Begin PBXBuildFile section */
|
/* Begin PBXBuildFile section */
|
||||||
|
7A000AA224C2EEDE001F5B00 /* Location.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A000AA124C2EEDE001F5B00 /* Location.swift */; };
|
||||||
7A051611241412CA00FC55AC /* SwiftDate in Frameworks */ = {isa = PBXBuildFile; productRef = 7A051610241412CA00FC55AC /* SwiftDate */; };
|
7A051611241412CA00FC55AC /* SwiftDate in Frameworks */ = {isa = PBXBuildFile; productRef = 7A051610241412CA00FC55AC /* SwiftDate */; };
|
||||||
7A0516162414EC1200FC55AC /* Differentiator in Frameworks */ = {isa = PBXBuildFile; productRef = 7A0516152414EC1200FC55AC /* Differentiator */; };
|
7A0516162414EC1200FC55AC /* Differentiator in Frameworks */ = {isa = PBXBuildFile; productRef = 7A0516152414EC1200FC55AC /* Differentiator */; };
|
||||||
7A0516182414EC1200FC55AC /* RxDataSources in Frameworks */ = {isa = PBXBuildFile; productRef = 7A0516172414EC1200FC55AC /* RxDataSources */; };
|
7A0516182414EC1200FC55AC /* RxDataSources in Frameworks */ = {isa = PBXBuildFile; productRef = 7A0516172414EC1200FC55AC /* RxDataSources */; };
|
||||||
@ -90,6 +91,7 @@
|
|||||||
/* End PBXBuildFile section */
|
/* End PBXBuildFile section */
|
||||||
|
|
||||||
/* Begin PBXFileReference section */
|
/* Begin PBXFileReference section */
|
||||||
|
7A000AA124C2EEDE001F5B00 /* Location.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Location.swift; sourceTree = "<group>"; };
|
||||||
7A0516192414FF0900FC55AC /* DateSection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DateSection.swift; sourceTree = "<group>"; };
|
7A0516192414FF0900FC55AC /* DateSection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DateSection.swift; sourceTree = "<group>"; };
|
||||||
7A1090E724A394F100B4F0B2 /* AudioRecordCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AudioRecordCell.swift; sourceTree = "<group>"; };
|
7A1090E724A394F100B4F0B2 /* AudioRecordCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AudioRecordCell.swift; sourceTree = "<group>"; };
|
||||||
7A1090E924A3A26300B4F0B2 /* AudioPlayer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AudioPlayer.swift; sourceTree = "<group>"; };
|
7A1090E924A3A26300B4F0B2 /* AudioPlayer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AudioPlayer.swift; sourceTree = "<group>"; };
|
||||||
@ -266,6 +268,7 @@
|
|||||||
7A11474323FF06CA00B424AF /* Api.swift */,
|
7A11474323FF06CA00B424AF /* Api.swift */,
|
||||||
7A27ADF6249FEF690035F39E /* Recorder.swift */,
|
7A27ADF6249FEF690035F39E /* Recorder.swift */,
|
||||||
7A1090E924A3A26300B4F0B2 /* AudioPlayer.swift */,
|
7A1090E924A3A26300B4F0B2 /* AudioPlayer.swift */,
|
||||||
|
7A000AA124C2EEDE001F5B00 /* Location.swift */,
|
||||||
);
|
);
|
||||||
path = Utils;
|
path = Utils;
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
@ -537,6 +540,7 @@
|
|||||||
7A64AE752469DFB600ABE48E /* MediaBrowserViewController.swift in Sources */,
|
7A64AE752469DFB600ABE48E /* MediaBrowserViewController.swift in Sources */,
|
||||||
7A64AE732469DFB600ABE48E /* DismissAnimationController.swift in Sources */,
|
7A64AE732469DFB600ABE48E /* DismissAnimationController.swift in Sources */,
|
||||||
7A64AE812469E16100ABE48E /* ProgressAnimatedView.swift in Sources */,
|
7A64AE812469E16100ABE48E /* ProgressAnimatedView.swift in Sources */,
|
||||||
|
7A000AA224C2EEDE001F5B00 /* Location.swift in Sources */,
|
||||||
7A7547E024032CB6004E8406 /* VehiclePhotoCell.swift in Sources */,
|
7A7547E024032CB6004E8406 /* VehiclePhotoCell.swift in Sources */,
|
||||||
);
|
);
|
||||||
runOnlyForDeploymentPostprocessing = 0;
|
runOnlyForDeploymentPostprocessing = 0;
|
||||||
@ -683,7 +687,7 @@
|
|||||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||||
CODE_SIGN_ENTITLEMENTS = AutoCat/AutoCat.entitlements;
|
CODE_SIGN_ENTITLEMENTS = AutoCat/AutoCat.entitlements;
|
||||||
CODE_SIGN_STYLE = Automatic;
|
CODE_SIGN_STYLE = Automatic;
|
||||||
CURRENT_PROJECT_VERSION = 20;
|
CURRENT_PROJECT_VERSION = 21;
|
||||||
DEVELOPMENT_TEAM = 46DTTB8X4S;
|
DEVELOPMENT_TEAM = 46DTTB8X4S;
|
||||||
INFOPLIST_FILE = AutoCat/Info.plist;
|
INFOPLIST_FILE = AutoCat/Info.plist;
|
||||||
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
|
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
|
||||||
@ -705,7 +709,7 @@
|
|||||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||||
CODE_SIGN_ENTITLEMENTS = AutoCat/AutoCat.entitlements;
|
CODE_SIGN_ENTITLEMENTS = AutoCat/AutoCat.entitlements;
|
||||||
CODE_SIGN_STYLE = Automatic;
|
CODE_SIGN_STYLE = Automatic;
|
||||||
CURRENT_PROJECT_VERSION = 20;
|
CURRENT_PROJECT_VERSION = 21;
|
||||||
DEVELOPMENT_TEAM = 46DTTB8X4S;
|
DEVELOPMENT_TEAM = 46DTTB8X4S;
|
||||||
INFOPLIST_FILE = AutoCat/Info.plist;
|
INFOPLIST_FILE = AutoCat/Info.plist;
|
||||||
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
|
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
|
||||||
|
|||||||
@ -59,6 +59,8 @@ class RecordsController: UIViewController, UITableViewDelegate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
self.tableView.rx.setDelegate(self).disposed(by: self.bag)
|
self.tableView.rx.setDelegate(self).disposed(by: self.bag)
|
||||||
|
|
||||||
|
LocationManager.requestCurrentLocation().subscribe().disposed(by: self.bag)
|
||||||
}
|
}
|
||||||
|
|
||||||
override func viewDidAppear(_ animated: Bool) {
|
override func viewDidAppear(_ animated: Bool) {
|
||||||
|
|||||||
@ -2,6 +2,8 @@
|
|||||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||||
<plist version="1.0">
|
<plist version="1.0">
|
||||||
<dict>
|
<dict>
|
||||||
|
<key>NSLocationWhenInUseUsageDescription</key>
|
||||||
|
<string>Access is needed for storing locations of vehicles</string>
|
||||||
<key>CFBundleDevelopmentRegion</key>
|
<key>CFBundleDevelopmentRegion</key>
|
||||||
<string>$(DEVELOPMENT_LANGUAGE)</string>
|
<string>$(DEVELOPMENT_LANGUAGE)</string>
|
||||||
<key>CFBundleExecutable</key>
|
<key>CFBundleExecutable</key>
|
||||||
|
|||||||
82
AutoCat/Utils/Location.swift
Normal file
82
AutoCat/Utils/Location.swift
Normal file
@ -0,0 +1,82 @@
|
|||||||
|
import Foundation
|
||||||
|
import RxSwift
|
||||||
|
import RxCocoa
|
||||||
|
import CoreLocation
|
||||||
|
|
||||||
|
struct VehicleEvent {
|
||||||
|
var date: Date
|
||||||
|
var latitude: Double
|
||||||
|
var longitude: Double
|
||||||
|
var speed: Double
|
||||||
|
var direction: Double
|
||||||
|
}
|
||||||
|
|
||||||
|
class RxLocationManagerDelegateProxy: DelegateProxy<CLLocationManager, CLLocationManagerDelegate>, DelegateProxyType, CLLocationManagerDelegate {
|
||||||
|
|
||||||
|
init(locationManager: ParentObject) {
|
||||||
|
super.init(parentObject: locationManager, delegateProxy: RxLocationManagerDelegateProxy.self)
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - DelegateProxyType
|
||||||
|
|
||||||
|
static func registerKnownImplementations() {
|
||||||
|
self.register { RxLocationManagerDelegateProxy(locationManager: $0) }
|
||||||
|
}
|
||||||
|
|
||||||
|
static func currentDelegate(for object: CLLocationManager) -> CLLocationManagerDelegate? {
|
||||||
|
return object.delegate
|
||||||
|
}
|
||||||
|
|
||||||
|
static func setCurrentDelegate(_ delegate: CLLocationManagerDelegate?, to object: CLLocationManager) {
|
||||||
|
object.delegate = delegate
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
extension Reactive where Base: CLLocationManager {
|
||||||
|
var delegate: DelegateProxy<CLLocationManager, CLLocationManagerDelegate> {
|
||||||
|
return RxLocationManagerDelegateProxy.proxy(for: base)
|
||||||
|
}
|
||||||
|
|
||||||
|
var didChangeAuthorization: ControlEvent<CLAuthorizationStatus> {
|
||||||
|
let sel = #selector((CLLocationManagerDelegate.locationManager(_:didChangeAuthorization:)! as (CLLocationManagerDelegate) -> (CLLocationManager, CLAuthorizationStatus) -> Void))
|
||||||
|
let source: Observable<CLAuthorizationStatus> = delegate.methodInvoked(sel)
|
||||||
|
.map { arg in
|
||||||
|
let status = arg[1] as! CLAuthorizationStatus
|
||||||
|
return status
|
||||||
|
}
|
||||||
|
return ControlEvent(events: source)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class LocationManager: {
|
||||||
|
static let shared = LocationManager()
|
||||||
|
|
||||||
|
private let manager = CLLocationManager()
|
||||||
|
private let bag = DisposeBag()
|
||||||
|
|
||||||
|
private func checkPermissions() -> Single<Void> {
|
||||||
|
return Single<Void>.create { observer in
|
||||||
|
switch CLLocationManager.authorizationStatus() {
|
||||||
|
case .authorizedWhenInUse:
|
||||||
|
observer(.success(()))
|
||||||
|
break
|
||||||
|
case .notDetermined:
|
||||||
|
self.manager.requestWhenInUseAuthorization()
|
||||||
|
_ = self.manager.rx.didChangeAuthorization.first().subscribe(onSuccess: { status in
|
||||||
|
|
||||||
|
}, onError: { observer(.error($0)) })
|
||||||
|
default:
|
||||||
|
observer(.error(NSError(domain: "", code: 0, userInfo: [NSLocalizedDescriptionKey: "Location permission error"])))
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
return Disposables.create { }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func requestCurrentLocation() -> Single<VehicleEvent> {
|
||||||
|
return self.checkPermissions().map {
|
||||||
|
return VehicleEvent()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user