Skip to content

Commit b13c467

Browse files
committed
Use granted when available
1 parent 852524c commit b13c467

File tree

6 files changed

+25
-21
lines changed

6 files changed

+25
-21
lines changed

ios/Calendars/RNPermissionHandlerCalendars.mm

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,16 @@ - (void)requestWithResolver:(void (^ _Nonnull)(RNPermissionStatus))resolve
3838
#if TARGET_OS_TV
3939
resolve(RNPermissionStatusNotAvailable);
4040
#else
41-
EKEventStore *store = [EKEventStore new];
42-
43-
void (^completion)(BOOL, NSError * _Nullable) = ^(__unused BOOL granted, NSError * _Nullable error) {
41+
void (^completion)(BOOL, NSError * _Nullable) = ^(BOOL granted, NSError * _Nullable error) {
4442
if (error != nil) {
4543
reject(error);
4644
} else {
4745
[RNPermissions flagAsRequested:[[self class] handlerUniqueId]];
4846

47+
if (granted) {
48+
return resolve(RNPermissionStatusAuthorized);
49+
}
50+
4951
switch ([EKEventStore authorizationStatusForEntityType:EKEntityTypeEvent]) {
5052
case EKAuthorizationStatusNotDetermined:
5153
return resolve(RNPermissionStatusNotDetermined);
@@ -60,6 +62,8 @@ - (void)requestWithResolver:(void (^ _Nonnull)(RNPermissionStatus))resolve
6062
}
6163
};
6264

65+
EKEventStore *store = [EKEventStore new];
66+
6367
if (@available(iOS 17.0, *)) {
6468
[store requestFullAccessToEventsWithCompletion:completion];
6569
} else {

ios/CalendarsWriteOnly/RNPermissionHandlerCalendarsWriteOnly.mm

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,16 @@ - (void)requestWithResolver:(void (^ _Nonnull)(RNPermissionStatus))resolve
3737
#if TARGET_OS_TV
3838
resolve(RNPermissionStatusNotAvailable);
3939
#else
40-
EKEventStore *store = [EKEventStore new];
41-
42-
void (^completion)(BOOL, NSError * _Nullable) = ^(__unused BOOL granted, NSError * _Nullable error) {
40+
void (^completion)(BOOL, NSError * _Nullable) = ^(BOOL granted, NSError * _Nullable error) {
4341
if (error != nil) {
4442
reject(error);
4543
} else {
46-
resolve([self currentStatus]);
44+
resolve(granted ? RNPermissionStatusAuthorized : [self currentStatus]);
4745
}
4846
};
4947

48+
EKEventStore *store = [EKEventStore new];
49+
5050
if (@available(iOS 17.0, *)) {
5151
[store requestWriteOnlyAccessToEventsWithCompletion:completion];
5252
} else {

ios/Camera/RNPermissionHandlerCamera.mm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ - (void)requestWithResolver:(void (^ _Nonnull)(RNPermissionStatus))resolve
3333
rejecter:(void (^ _Nonnull)(NSError * _Nonnull))reject {
3434
if (@available(iOS 7.0, tvOS 17.0, *)) {
3535
[AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo
36-
completionHandler:^(__unused BOOL granted) {
37-
resolve([self currentStatus]);
36+
completionHandler:^(BOOL granted) {
37+
resolve(granted ? RNPermissionStatusAuthorized : [self currentStatus]);
3838
}];
3939
} else {
4040
resolve([self currentStatus]);

ios/Contacts/RNPermissionHandlerContacts.mm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ - (void)requestWithResolver:(void (^ _Nonnull)(RNPermissionStatus))resolve
3939
resolve(RNPermissionStatusNotAvailable);
4040
#else
4141
[[CNContactStore new] requestAccessForEntityType:CNEntityTypeContacts
42-
completionHandler:^(__unused BOOL granted, NSError * _Nullable error) {
42+
completionHandler:^(BOOL granted, NSError * _Nullable error) {
4343
if (error != nil && error.code != 100) { // error code 100 is permission denied
4444
reject(error);
4545
} else {
46-
resolve([self currentStatus]);
46+
resolve(granted ? RNPermissionStatusAuthorized : [self currentStatus]);
4747
}
4848
}];
4949
#endif

ios/Microphone/RNPermissionHandlerMicrophone.mm

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,17 @@ - (RNPermissionStatus)currentStatus {
4040

4141
- (void)requestWithResolver:(void (^ _Nonnull)(RNPermissionStatus))resolve
4242
rejecter:(void (^ _Nonnull)(NSError * _Nonnull))reject {
43+
void (^completion)(BOOL) = ^(BOOL granted) {
44+
resolve(granted ? RNPermissionStatusAuthorized : [self currentStatus]);
45+
};
46+
4347
if (@available(iOS 17.0, tvOS 17.0, *)) {
44-
[AVAudioApplication requestRecordPermissionWithCompletionHandler:^(__unused BOOL granted) {
45-
resolve([self currentStatus]);
46-
}];
48+
[AVAudioApplication requestRecordPermissionWithCompletionHandler:completion];
4749
} else {
4850
#if TARGET_OS_TV
4951
resolve([self currentStatus]);
5052
#else
51-
[[AVAudioSession sharedInstance] requestRecordPermission:^(__unused BOOL granted) {
52-
resolve([self currentStatus]);
53-
}];
53+
[[AVAudioSession sharedInstance] requestRecordPermission:completion];
5454
#endif
5555
}
5656
}

ios/Reminders/RNPermissionHandlerReminders.mm

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,16 @@ - (void)requestWithResolver:(void (^ _Nonnull)(RNPermissionStatus))resolve
3737
#if TARGET_OS_TV
3838
resolve(RNPermissionStatusNotAvailable);
3939
#else
40-
EKEventStore *store = [EKEventStore new];
41-
42-
void (^completion)(BOOL, NSError * _Nullable) = ^(__unused BOOL granted, NSError * _Nullable error) {
40+
void (^completion)(BOOL, NSError * _Nullable) = ^(BOOL granted, NSError * _Nullable error) {
4341
if (error != nil) {
4442
reject(error);
4543
} else {
46-
resolve([self currentStatus]);
44+
resolve(granted ? RNPermissionStatusAuthorized : [self currentStatus]);
4745
}
4846
};
4947

48+
EKEventStore *store = [EKEventStore new];
49+
5050
if (@available(iOS 17.0, *)) {
5151
[store requestFullAccessToRemindersWithCompletion:completion];
5252
} else {

0 commit comments

Comments
 (0)