This repository was archived by the owner on May 15, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +11
-2
lines changed Expand file tree Collapse file tree 2 files changed +11
-2
lines changed Original file line number Diff line number Diff line change @@ -19,7 +19,7 @@ public static partial class Geolocation
19
19
20
20
static async Task < Location > PlatformLastKnownLocationAsync ( )
21
21
{
22
- await Permissions . EnsureGrantedAsync < Permissions . LocationWhenInUse > ( ) ;
22
+ await Permissions . EnsureGrantedOrRestrictedAsync < Permissions . LocationWhenInUse > ( ) ;
23
23
24
24
var lm = Platform . LocationManager ;
25
25
AndroidLocation bestLocation = null ;
@@ -37,7 +37,7 @@ static async Task<Location> PlatformLastKnownLocationAsync()
37
37
38
38
static async Task < Location > PlatformLocationAsync ( GeolocationRequest request , CancellationToken cancellationToken )
39
39
{
40
- await Permissions . EnsureGrantedAsync < Permissions . LocationWhenInUse > ( ) ;
40
+ await Permissions . EnsureGrantedOrRestrictedAsync < Permissions . LocationWhenInUse > ( ) ;
41
41
42
42
var locationManager = Platform . LocationManager ;
43
43
Original file line number Diff line number Diff line change @@ -29,6 +29,15 @@ internal static async Task EnsureGrantedAsync<TPermission>()
29
29
throw new PermissionException ( $ "{ typeof ( TPermission ) . Name } permission was not granted: { status } ") ;
30
30
}
31
31
32
+ internal static async Task EnsureGrantedOrRestrictedAsync < TPermission > ( )
33
+ where TPermission : BasePermission , new ( )
34
+ {
35
+ var status = await RequestAsync < TPermission > ( ) ;
36
+
37
+ if ( status != PermissionStatus . Granted && status != PermissionStatus . Restricted )
38
+ throw new PermissionException ( $ "{ typeof ( TPermission ) . Name } permission was not granted or restricted: { status } ") ;
39
+ }
40
+
32
41
public abstract partial class BasePermission
33
42
{
34
43
[ Preserve ]
You can’t perform that action at this time.
0 commit comments