Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions permission_handler_apple/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 9.4.8

* Fixed iOS permission request state not being reset when app enters background, causing subsequent requests to fail with `ERROR_ALREADY_REQUESTING_PERMISSIONS`.

## 9.4.7

* Increases minimum supported Flutter version to 3.3.0, and removes code only
Expand Down
26 changes: 26 additions & 0 deletions permission_handler_apple/ios/Classes/PermissionHandlerPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ + (void)registerWithRegistrar:(NSObject <FlutterPluginRegistrar> *)registrar {
binaryMessenger:[registrar messenger]];
PermissionManager *permissionManager = [[PermissionManager alloc] initWithStrategyInstances];
PermissionHandlerPlugin *instance = [[PermissionHandlerPlugin alloc] initWithPermissionManager:permissionManager];

[[NSNotificationCenter defaultCenter]
addObserver:instance
selector:@selector(handleApplicationDidEnterBackground:)
name:UIApplicationDidEnterBackgroundNotification
object:nil];

[registrar addMethodCallDelegate:instance channel:channel];
}

Expand Down Expand Up @@ -62,4 +69,23 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result
}
}

- (void)handleApplicationDidEnterBackground:(NSNotification *)notification {
if (_methodResult != nil) {
#ifdef DEBUG
NSLog(@"[PermissionHandler] App backgrounded with pending permission request. Cancelling request.");
#endif

_methodResult([FlutterError
errorWithCode:@"REQUEST_INTERRUPTED"
message:@"Permission request was interrupted because the app entered background"
details:nil]);

_methodResult = nil;
}
}

- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
}

@end