Skip to content

Commit 5636e88

Browse files
committed
Fixes #5 (iOS 11 fixes)
1 parent 0547cee commit 5636e88

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

Sources/CLLocationManager+Promise.swift

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ extension CLLocationManager {
8888
*/
8989
@available(iOS 8, *)
9090
public class func requestAuthorization(type: RequestAuthorizationType = .automatic) -> Promise<CLAuthorizationStatus> {
91-
return AuthorizationCatcher(auther: auther(type)).promise
91+
return AuthorizationCatcher(auther: auther(type), type: type).promise
9292
}
9393
}
9494

@@ -97,14 +97,15 @@ private class AuthorizationCatcher: CLLocationManager, CLLocationManagerDelegate
9797
let (promise, fulfill, _) = Promise<CLAuthorizationStatus>.pending()
9898
var retainCycle: AnyObject?
9999

100-
init(auther: (CLLocationManager)->()) {
100+
init(auther: (CLLocationManager) -> Void, type: CLLocationManager.RequestAuthorizationType) {
101101
super.init()
102102
let status = CLLocationManager.authorizationStatus()
103-
if status == .notDetermined {
103+
switch (status, type) {
104+
case (.notDetermined, _), (.authorizedWhenInUse, .always), (.authorizedWhenInUse, .automatic):
104105
delegate = self
105106
auther(self)
106107
retainCycle = self
107-
} else {
108+
default:
108109
fulfill(status)
109110
}
110111
}
@@ -128,12 +129,12 @@ private func auther(_ requestAuthorizationType: CLLocationManager.RequestAuthori
128129

129130
switch requestAuthorizationType {
130131
case .automatic:
131-
let always = hasInfoPlistKey("NSLocationAlwaysUsageDescription")
132-
let whenInUse = hasInfoPlistKey("NSLocationWhenInUseUsageDescription")
132+
let always = hasInfoPlistKey("NSLocationAlwaysUsageDescription") || hasInfoPlistKey("NSLocationAlwaysAndWhenInUsageDescription")
133+
let whenInUse = { hasInfoPlistKey("NSLocationWhenInUseUsageDescription") }
133134
if always {
134135
manager.requestAlwaysAuthorization()
135136
} else {
136-
if !whenInUse { NSLog("PromiseKit: Warning: `NSLocationWhenInUseUsageDescription` key not set") }
137+
if !whenInUse() { NSLog("PromiseKit: Warning: `NSLocationWhenInUseUsageDescription` key not set") }
137138
manager.requestWhenInUseAuthorization()
138139
}
139140
case .whenInUse:

0 commit comments

Comments
 (0)