@@ -104,6 +104,10 @@ @implementation RCTConvert(RNPermission)
104104
105105@end
106106
107+ @interface RNPermissions ()
108+ @property (nonatomic , strong ) NSMutableDictionary <NSString *, id<RNPermissionHandler>> *_Nonnull handlers;
109+ @end
110+
107111@implementation RNPermissions
108112
109113RCT_EXPORT_MODULE ();
@@ -225,6 +229,18 @@ - (NSString *)stringForStatus:(RNPermissionStatus)status {
225229 }
226230}
227231
232+ - (NSString *)insertHandler : (id <RNPermissionHandler>)handler {
233+ if (_handlers == nil ){
234+ _handlers = [NSMutableDictionary new ];
235+ }
236+
237+ NSString *randomId = [[NSUUID UUID ] UUIDString ];
238+
239+ [_handlers setObject: handler forKey: randomId];
240+
241+ return randomId;
242+ }
243+
228244+ (bool )isFlaggedAsRequested : (NSString * _Nonnull)handlerId {
229245 NSArray <NSString *> *requested = [[NSUserDefaults standardUserDefaults ] arrayForKey: SETTING_KEY];
230246 return requested == nil ? false : [requested containsObject: handlerId];
@@ -271,13 +287,19 @@ + (void)flagAsRequested:(NSString * _Nonnull)handlerId {
271287 rejecter:(RCTPromiseRejectBlock)reject) {
272288 id <RNPermissionHandler> handler = [self handlerForPermission: permission];
273289
290+ NSString *randomId = [self insertHandler: handler];
291+
274292 [handler checkWithResolver: ^(RNPermissionStatus status) {
275293 NSString *strStatus = [self stringForStatus: status];
276294 NSLog (@" [react-native-permissions] %@ permission checked: %@ " , [[handler class ] handlerUniqueId ], strStatus);
277295 resolve (strStatus);
296+
297+ [self .handlers removeObjectForKey: randomId];
278298 } rejecter: ^(NSError *error) {
279299 NSLog (@" [react-native-permissions] %@ permission failed: %@ " , [[handler class ] handlerUniqueId ], error.localizedDescription );
280300 reject ([NSString stringWithFormat: @" %ld " , (long )error.code], error.localizedDescription , error);
301+
302+ [self .handlers removeObjectForKey: randomId];
281303 }];
282304}
283305
@@ -287,13 +309,19 @@ + (void)flagAsRequested:(NSString * _Nonnull)handlerId {
287309 rejecter:(RCTPromiseRejectBlock)reject) {
288310 id <RNPermissionHandler> handler = [self handlerForPermission: permission];
289311
312+ NSString *randomId = [self insertHandler: handler];
313+
290314 [handler requestWithResolver: ^(RNPermissionStatus status) {
291315 NSString *strStatus = [self stringForStatus: status];
292316 NSLog (@" [react-native-permissions] %@ permission checked: %@ " , [[handler class ] handlerUniqueId ], strStatus);
293317 resolve (strStatus);
318+
319+ [self .handlers removeObjectForKey: randomId];
294320 } rejecter: ^(NSError *error) {
295321 NSLog (@" [react-native-permissions] %@ permission failed: %@ " , [[handler class ] handlerUniqueId ], error.localizedDescription );
296322 reject ([NSString stringWithFormat: @" %ld " , (long )error.code], error.localizedDescription , error);
323+
324+ [self .handlers removeObjectForKey: randomId];
297325 }];
298326}
299327
0 commit comments