@@ -88,7 +88,7 @@ extension CLLocationManager {
88
88
*/
89
89
@available ( iOS 8 , * )
90
90
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
92
92
}
93
93
}
94
94
@@ -97,14 +97,15 @@ private class AuthorizationCatcher: CLLocationManager, CLLocationManagerDelegate
97
97
let ( promise, fulfill, _) = Promise< CLAuthorizationStatus> . pending( )
98
98
var retainCycle : AnyObject ?
99
99
100
- init ( auther: ( CLLocationManager ) -> ( ) ) {
100
+ init ( auther: ( CLLocationManager ) -> Void , type : CLLocationManager . RequestAuthorizationType ) {
101
101
super. init ( )
102
102
let status = CLLocationManager . authorizationStatus ( )
103
- if status == . notDetermined {
103
+ switch ( status, type) {
104
+ case ( . notDetermined, _) , ( . authorizedWhenInUse, . always) , ( . authorizedWhenInUse, . automatic) :
104
105
delegate = self
105
106
auther ( self )
106
107
retainCycle = self
107
- } else {
108
+ default :
108
109
fulfill ( status)
109
110
}
110
111
}
@@ -128,12 +129,12 @@ private func auther(_ requestAuthorizationType: CLLocationManager.RequestAuthori
128
129
129
130
switch requestAuthorizationType {
130
131
case . automatic:
131
- let always = hasInfoPlistKey ( " NSLocationAlwaysUsageDescription " )
132
- let whenInUse = hasInfoPlistKey ( " NSLocationWhenInUseUsageDescription " )
132
+ let always = hasInfoPlistKey ( " NSLocationAlwaysUsageDescription " ) || hasInfoPlistKey ( " NSLocationAlwaysAndWhenInUsageDescription " )
133
+ let whenInUse = { hasInfoPlistKey ( " NSLocationWhenInUseUsageDescription " ) }
133
134
if always {
134
135
manager. requestAlwaysAuthorization ( )
135
136
} else {
136
- if !whenInUse { NSLog ( " PromiseKit: Warning: `NSLocationWhenInUseUsageDescription` key not set " ) }
137
+ if !whenInUse( ) { NSLog ( " PromiseKit: Warning: `NSLocationWhenInUseUsageDescription` key not set " ) }
137
138
manager. requestWhenInUseAuthorization ( )
138
139
}
139
140
case . whenInUse:
0 commit comments