@@ -23,29 +23,31 @@ + (NSString * _Nonnull)handlerUniqueId {
23
23
- (void )checkWithResolver : (RCTPromiseResolveBlock _Nonnull)resolve
24
24
rejecter : (RCTPromiseRejectBlock _Nonnull)reject {
25
25
if (@available (iOS 14 , *)) {
26
- if (![CLLocationManager locationServicesEnabled ]) {
27
- return reject (@" cannot_check_location_accuracy" , @" Location services are disabled" , nil );
28
- }
29
-
30
- switch ([CLLocationManager authorizationStatus ]) {
31
- case kCLAuthorizationStatusNotDetermined :
32
- return reject (@" cannot_check_location_accuracy" , @" Location permission hasn't been requested first" , nil );
33
- case kCLAuthorizationStatusRestricted :
34
- case kCLAuthorizationStatusDenied :
35
- return reject (@" cannot_check_location_accuracy" , @" Location permission has been blocked by the user" , nil );
36
- case kCLAuthorizationStatusAuthorizedWhenInUse :
37
- case kCLAuthorizationStatusAuthorizedAlways :
38
- break ;
39
- }
40
-
41
- CLLocationManager *locationManager = [CLLocationManager new ];
42
-
43
- switch (locationManager.accuracyAuthorization ) {
44
- case CLAccuracyAuthorizationFullAccuracy:
45
- return resolve (@" full" );
46
- case CLAccuracyAuthorizationReducedAccuracy:
47
- return resolve (@" reduced" );
48
- }
26
+ dispatch_async (dispatch_get_global_queue (DISPATCH_QUEUE_PRIORITY_DEFAULT, 0 ), ^{
27
+ if (![CLLocationManager locationServicesEnabled ]) {
28
+ return reject (@" cannot_check_location_accuracy" , @" Location services are disabled" , nil );
29
+ }
30
+
31
+ switch ([CLLocationManager authorizationStatus ]) {
32
+ case kCLAuthorizationStatusNotDetermined :
33
+ return reject (@" cannot_check_location_accuracy" , @" Location permission hasn't been requested first" , nil );
34
+ case kCLAuthorizationStatusRestricted :
35
+ case kCLAuthorizationStatusDenied :
36
+ return reject (@" cannot_check_location_accuracy" , @" Location permission has been blocked by the user" , nil );
37
+ case kCLAuthorizationStatusAuthorizedWhenInUse :
38
+ case kCLAuthorizationStatusAuthorizedAlways :
39
+ break ;
40
+ }
41
+
42
+ CLLocationManager *locationManager = [CLLocationManager new ];
43
+
44
+ switch (locationManager.accuracyAuthorization ) {
45
+ case CLAccuracyAuthorizationFullAccuracy:
46
+ return resolve (@" full" );
47
+ case CLAccuracyAuthorizationReducedAccuracy:
48
+ return resolve (@" reduced" );
49
+ }
50
+ });
49
51
} else {
50
52
reject (@" cannot_check_location_accuracy" , @" Only available on iOS 14 or higher" , nil );
51
53
}
@@ -55,43 +57,45 @@ - (void)requestWithPurposeKey:(NSString * _Nonnull)purposeKey
55
57
resolver : (RCTPromiseResolveBlock _Nonnull)resolve
56
58
rejecter : (RCTPromiseRejectBlock _Nonnull)reject {
57
59
if (@available (iOS 14 , *)) {
58
- if (![CLLocationManager locationServicesEnabled ]) {
59
- return reject (@" cannot_request_location_accuracy" , @" Location services are disabled" , nil );
60
- }
61
-
62
- switch ([CLLocationManager authorizationStatus ]) {
63
- case kCLAuthorizationStatusNotDetermined :
64
- return reject (@" cannot_request_location_accuracy" , @" Location permission hasn't been requested first" , nil );
65
- case kCLAuthorizationStatusRestricted :
66
- case kCLAuthorizationStatusDenied :
67
- return reject (@" cannot_request_location_accuracy" , @" Location permission has been blocked by the user" , nil );
68
- case kCLAuthorizationStatusAuthorizedWhenInUse :
69
- case kCLAuthorizationStatusAuthorizedAlways :
70
- break ;
71
- }
72
-
73
- CLLocationManager *locationManager = [CLLocationManager new ];
74
-
75
- switch (locationManager.accuracyAuthorization ) {
76
- case CLAccuracyAuthorizationFullAccuracy:
77
- return resolve (@" full" ); // resolve early if full accuracy is already granted
78
- case CLAccuracyAuthorizationReducedAccuracy:
79
- break ;
80
- }
81
-
82
- [locationManager requestTemporaryFullAccuracyAuthorizationWithPurposeKey: purposeKey
83
- completion: ^(NSError * _Nullable error) {
84
- if (error) {
85
- reject ([NSString stringWithFormat: @" %ld " , (long )error.code], error.localizedDescription , error);
86
- } else {
87
- switch (locationManager.accuracyAuthorization ) {
88
- case CLAccuracyAuthorizationFullAccuracy:
89
- return resolve (@" full" );
90
- case CLAccuracyAuthorizationReducedAccuracy:
91
- return resolve (@" reduced" );
92
- }
60
+ dispatch_async (dispatch_get_global_queue (DISPATCH_QUEUE_PRIORITY_DEFAULT, 0 ), ^{
61
+ if (![CLLocationManager locationServicesEnabled ]) {
62
+ return reject (@" cannot_request_location_accuracy" , @" Location services are disabled" , nil );
93
63
}
94
- }];
64
+
65
+ switch ([CLLocationManager authorizationStatus ]) {
66
+ case kCLAuthorizationStatusNotDetermined :
67
+ return reject (@" cannot_request_location_accuracy" , @" Location permission hasn't been requested first" , nil );
68
+ case kCLAuthorizationStatusRestricted :
69
+ case kCLAuthorizationStatusDenied :
70
+ return reject (@" cannot_request_location_accuracy" , @" Location permission has been blocked by the user" , nil );
71
+ case kCLAuthorizationStatusAuthorizedWhenInUse :
72
+ case kCLAuthorizationStatusAuthorizedAlways :
73
+ break ;
74
+ }
75
+
76
+ CLLocationManager *locationManager = [CLLocationManager new ];
77
+
78
+ switch (locationManager.accuracyAuthorization ) {
79
+ case CLAccuracyAuthorizationFullAccuracy:
80
+ return resolve (@" full" ); // resolve early if full accuracy is already granted
81
+ case CLAccuracyAuthorizationReducedAccuracy:
82
+ break ;
83
+ }
84
+
85
+ [locationManager requestTemporaryFullAccuracyAuthorizationWithPurposeKey: purposeKey
86
+ completion: ^(NSError * _Nullable error) {
87
+ if (error) {
88
+ reject ([NSString stringWithFormat: @" %ld " , (long )error.code], error.localizedDescription , error);
89
+ } else {
90
+ switch (locationManager.accuracyAuthorization ) {
91
+ case CLAccuracyAuthorizationFullAccuracy:
92
+ return resolve (@" full" );
93
+ case CLAccuracyAuthorizationReducedAccuracy:
94
+ return resolve (@" reduced" );
95
+ }
96
+ }
97
+ }];
98
+ });
95
99
} else {
96
100
reject (@" cannot_request_location_accuracy" , @" Only available on iOS 14 or higher" , nil );
97
101
}
0 commit comments