-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRALocationKitConvenience.swift
37 lines (33 loc) · 1.74 KB
/
RALocationKitConvenience.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
//
// RALocationKitConvenience.swift
// RALocationKitLab
//
// Created by Marcus Ronélius on 2016-01-13.
// Copyright © 2016 Ronelium Applications. All rights reserved.
//
import Foundation
import CoreLocation
extension RALocationKitClient {
func getCurrentLocation(completionHandler: (location: CLLocation?, error: NSError?) -> Void) {
do {
try updateLocation({ (location, error) -> Void in
if let location = location {
completionHandler(location: location, error: nil)
} else {
// Error, should occur if locationManager fails retreiving location or if user is not authorized after changing status
completionHandler(location: nil, error: self.generateNSError(error!))
}
})
} catch RALocationKitError.BadAuthorization(AuthorizationStatus.Restricted) {
completionHandler(location: nil, error: self.generateNSError(RALocationKitError.BadAuthorization(AuthorizationStatus.Restricted)))
} catch RALocationKitError.BadAuthorization(AuthorizationStatus.Denied) {
completionHandler(location: nil, error: self.generateNSError(RALocationKitError.BadAuthorization(AuthorizationStatus.Denied)))
} catch RALocationKitError.BadAuthorization(AuthorizationStatus.NotDetermined) {
completionHandler(location: nil, error: self.generateNSError(RALocationKitError.BadAuthorization(AuthorizationStatus.NotDetermined)))
} catch let unknownError {
// Shouldnt come here
print(unknownError)
completionHandler(location: nil, error: self.generateNSError(RALocationKitError.BadAuthorization(.GeneralError)))
}
}
}