Skip to content

Commit 0e25780

Browse files
committed
Request LOCATION_ALWAYS when app is focused
1 parent 9bb28b9 commit 0e25780

File tree

3 files changed

+20
-7
lines changed

3 files changed

+20
-7
lines changed

example/ios/Podfile.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1575,7 +1575,7 @@ PODS:
15751575
- React-logger (= 0.76.2)
15761576
- React-perflogger (= 0.76.2)
15771577
- React-utils (= 0.76.2)
1578-
- RNPermissions (5.2.4):
1578+
- RNPermissions (5.2.5):
15791579
- DoubleConversion
15801580
- glog
15811581
- hermes-engine
@@ -1893,7 +1893,7 @@ SPEC CHECKSUMS:
18931893
React-utils: c8c0c746031419a29cfd8c72a394fdeac0684a84
18941894
ReactCodegen: a64e8f3a8bba0ecf88fce06c2874e021d55148f3
18951895
ReactCommon: 7b9403030ff3430ccffed63cd25c8aeab2a3ea7e
1896-
RNPermissions: b4fb8e8f51c37a7b471436eb84bbbb5939afd294
1896+
RNPermissions: 0612506047d8586206b105b9d91f08473c1f4bc1
18971897
RNVectorIcons: a24016b773380b1aa37fca501ec6b94a951890a0
18981898
SocketRocket: d4aabe649be1e368d1318fdf28a022d714d65748
18991899
Yoga: 96872ee462cfc43866ad013c8160d4ff6b85709b

ios/LocationAlways/RNPermissionHandlerLocationAlways.mm

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,28 @@ - (void)requestWithResolver:(void (^ _Nonnull)(RNPermissionStatus))resolve
4343
#if TARGET_OS_TV
4444
resolve(RNPermissionStatusNotAvailable);
4545
#else
46+
_resolve = resolve;
47+
48+
if ([[UIApplication sharedApplication] applicationState] == UIApplicationStateActive) {
49+
[self performRequest];
50+
} else {
51+
[[NSNotificationCenter defaultCenter] addObserver:self
52+
selector:@selector(performRequest)
53+
name:UIApplicationDidBecomeActiveNotification
54+
object:nil];
55+
}
56+
#endif
57+
}
58+
59+
- (void)performRequest {
60+
[[NSNotificationCenter defaultCenter] removeObserver:self];
61+
4662
CLAuthorizationStatus status = [CLLocationManager authorizationStatus];
4763

4864
if (status != kCLAuthorizationStatusNotDetermined && status != kCLAuthorizationStatusAuthorizedWhenInUse) {
49-
return resolve([self currentStatus]);
65+
return _resolve([self currentStatus]);
5066
}
5167

52-
_resolve = resolve;
53-
5468
_locationManager = [CLLocationManager new];
5569
[_locationManager setDelegate:self];
5670

@@ -65,7 +79,6 @@ - (void)requestWithResolver:(void (^ _Nonnull)(RNPermissionStatus))resolve
6579
}
6680

6781
[_locationManager requestAlwaysAuthorization];
68-
#endif
6982
}
7083

7184
- (void)onApplicationWillResignActive {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-permissions",
3-
"version": "5.2.4",
3+
"version": "5.2.5",
44
"license": "MIT",
55
"description": "An unified permissions API for React Native on iOS, Android and Windows",
66
"author": "Mathieu Acthernoene <[email protected]>",

0 commit comments

Comments
 (0)