Skip to content

Commit 4b67dcf

Browse files
authored
Permission fix (#216)
* use only when in use authorization on ios * updated docs
1 parent dfd522d commit 4b67dcf

File tree

3 files changed

+5
-21
lines changed

3 files changed

+5
-21
lines changed

compass-permissions-mobile/src/iosMain/kotlin/dev/jordond/compass/permissions/mobile/internal/LocationPermissionManagerDelegate.kt

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package dev.jordond.compass.permissions.mobile.internal
33
import platform.CoreLocation.CLAuthorizationStatus
44
import platform.CoreLocation.CLLocationManager
55
import platform.CoreLocation.CLLocationManagerDelegateProtocol
6-
import platform.Foundation.NSBundle
76
import platform.darwin.NSObject
87

98
internal class LocationPermissionManagerDelegate : NSObject(), CLLocationManagerDelegateProtocol {
@@ -12,18 +11,11 @@ internal class LocationPermissionManagerDelegate : NSObject(), CLLocationManager
1211

1312
private var permissionCallback: ((CLAuthorizationStatus) -> Unit)? = null
1413
private var requestPermissionCallback: ((CLAuthorizationStatus) -> Unit)? = null
15-
16-
private val useAlwaysAuthorization = canUseAlwaysAuthorization()
1714

1815
init {
1916
manager.delegate = this
2017
}
2118

22-
private fun canUseAlwaysAuthorization(): Boolean {
23-
return NSBundle.mainBundle.infoDictionary
24-
?.containsKey("NSLocationAlwaysAndWhenInUseUsageDescription") ?: false
25-
}
26-
2719
fun currentPermissionStatus(): CLAuthorizationStatus {
2820
return manager.authorizationStatus
2921
}
@@ -44,11 +36,7 @@ internal class LocationPermissionManagerDelegate : NSObject(), CLLocationManager
4436
callback(status)
4537
requestPermissionCallback = null
4638
}
47-
48-
if (useAlwaysAuthorization) {
49-
manager.requestAlwaysAuthorization()
50-
} else {
51-
manager.requestWhenInUseAuthorization()
52-
}
39+
40+
manager.requestWhenInUseAuthorization()
5341
}
5442
}

demo/iosApp/iosApp/Info.plist

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,5 @@
4848
</array>
4949
<key>NSLocationWhenInUseUsageDescription</key>
5050
<string>Its a demo about location</string>
51-
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
52-
<string>A demo about geolocation</string>
5351
</dict>
5452
</plist>

docs/setup/android-ios.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,15 @@ On Android you don't need to declare any location permission in your manifest si
4848

4949
#### iOS
5050

51-
On iOS you are required to edit your `info.plist` and add the following entries:
51+
On iOS you are required to edit your `info.plist` and add the following entry:
5252

5353
```xml
5454
<key>NSLocationWhenInUseUsageDescription</key>
5555
<string>Add a description for why you need this permission</string>
56-
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
57-
<string>Add a description for why you need this permission</string>
5856
```
5957

6058
{% hint style="info" %}
61-
Make sure you change the description for both permissions. You are required to explain to your users why you need their location. Check out the [Documentation](https://developer.apple.com/documentation/corelocation/requesting\_authorization\_to\_use\_location\_services#3385302\)).
59+
Make sure you change the description for the permission. You are required to explain to your users why you need their location. Check out the [Documentation](https://developer.apple.com/documentation/corelocation/requesting\_authorization\_to\_use\_location\_services#3385302\)).
6260
{% endhint %}
6361

64-
If you don't add these keys to your `info.plist`, you will encounter a runtime exception when requesting permissions.
62+
If you don't add this key to your `info.plist`, you will encounter a runtime exception when requesting permissions.

0 commit comments

Comments
 (0)