diff --git a/permission_handler/CHANGELOG.md b/permission_handler/CHANGELOG.md index f6a0505d0..105d6dc7c 100644 --- a/permission_handler/CHANGELOG.md +++ b/permission_handler/CHANGELOG.md @@ -1,3 +1,7 @@ +## 10.2.1 + +* Fixed an issue where App Tracking Transparency prompt may not show correctly on iOS in some situations. + ## 10.2.0 * Added support for the new Android 13 permissions: SCHEDULE_EXACT_ALARM, READ_MEDIA_IMAGES, READ_MEDIA_VIDEO and READ_MEDIA_AUDIO diff --git a/permission_handler/pubspec.yaml b/permission_handler/pubspec.yaml index 8a6b384b5..455017406 100644 --- a/permission_handler/pubspec.yaml +++ b/permission_handler/pubspec.yaml @@ -1,6 +1,6 @@ name: permission_handler description: Permission plugin for Flutter. This plugin provides a cross-platform (iOS, Android) API to request and check permissions. -version: 10.2.0 +version: 10.2.1 repository: https://github.com/baseflow/flutter-permission-handler issue_tracker: https://github.com/Baseflow/flutter-permission-handler/issues @@ -23,7 +23,7 @@ dependencies: sdk: flutter meta: ^1.7.0 permission_handler_android: ^10.2.0 - permission_handler_apple: ^9.0.7 + permission_handler_apple: ^9.0.8 permission_handler_windows: ^0.1.2 permission_handler_platform_interface: ^3.9.0 diff --git a/permission_handler_apple/ios/Classes/strategies/AppTrackingTransparencyPermissionStrategy.m b/permission_handler_apple/ios/Classes/strategies/AppTrackingTransparencyPermissionStrategy.m index 01537f4ca..cfde4292a 100644 --- a/permission_handler_apple/ios/Classes/strategies/AppTrackingTransparencyPermissionStrategy.m +++ b/permission_handler_apple/ios/Classes/strategies/AppTrackingTransparencyPermissionStrategy.m @@ -11,6 +11,27 @@ @implementation AppTrackingTransparencyPermissionStrategy +PermissionStatusHandler storedCompletionHandler = nil; + ++ (void)load { + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(handleAppBecomeActive) + name:UIApplicationDidBecomeActiveNotification + object:nil]; +} + ++ (void)handleAppBecomeActive { + if (@available(iOS 14, *)){ + if (storedCompletionHandler != nil) { + [ATTrackingManager requestTrackingAuthorizationWithCompletionHandler:^(ATTrackingManagerAuthorizationStatus status) { + PermissionStatus permissionStatus = [AppTrackingTransparencyPermissionStrategy parsePermission:status]; + storedCompletionHandler(permissionStatus); + storedCompletionHandler = nil; + }]; + } + } +} + - (PermissionStatus)checkPermissionStatus:(PermissionGroup)permission { if (@available(iOS 14, *)) { ATTrackingManagerAuthorizationStatus attPermission = [ATTrackingManager trackingAuthorizationStatus]; @@ -32,10 +53,17 @@ - (void)requestPermission:(PermissionGroup)permission completionHandler:(Permiss } if (@available(iOS 14, *)){ - [ATTrackingManager requestTrackingAuthorizationWithCompletionHandler:^(ATTrackingManagerAuthorizationStatus status) { - PermissionStatus permissionStatus = [AppTrackingTransparencyPermissionStrategy parsePermission:status]; - completionHandler(permissionStatus); - }]; + UIApplicationState state = [[UIApplication sharedApplication] applicationState]; + if (state == UIApplicationStateActive) { + [ATTrackingManager requestTrackingAuthorizationWithCompletionHandler:^(ATTrackingManagerAuthorizationStatus status) { + PermissionStatus permissionStatus = [AppTrackingTransparencyPermissionStrategy parsePermission:status]; + completionHandler(permissionStatus); + }]; + } else { + // If state is not UIApplicationStateActive, iOS will not show the dialog for requesting AppTrackingTransperancy permission. + // Store the completion handler and only start requesting when the app become Active again. + storedCompletionHandler = completionHandler; + } } else { completionHandler(PermissionStatusGranted); } diff --git a/permission_handler_apple/pubspec.yaml b/permission_handler_apple/pubspec.yaml index 16f7d21e6..2d1d72c83 100644 --- a/permission_handler_apple/pubspec.yaml +++ b/permission_handler_apple/pubspec.yaml @@ -1,6 +1,6 @@ name: permission_handler_apple description: Permission plugin for Flutter. This plugin provides the iOS API to request and check permissions. -version: 9.0.7 +version: 9.0.8 homepage: https://github.com/baseflow/flutter-permission-handler environment: