From a73ec3f5164bbc21ad0a9748ab58e862fb80b12f Mon Sep 17 00:00:00 2001 From: Peter WONG Date: Wed, 21 Dec 2022 17:01:36 +0800 Subject: [PATCH 1/3] Fix App Tracking Transparency request may fail to show. --- ...ppTrackingTransparencyPermissionStrategy.m | 36 ++++++++++++++++--- 1 file changed, 32 insertions(+), 4 deletions(-) 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); } From a9cbcf39a25da04ba071ee2134f71442a7cf2095 Mon Sep 17 00:00:00 2001 From: Peter WONG Date: Wed, 21 Dec 2022 17:27:04 +0800 Subject: [PATCH 2/3] update version --- permission_handler/CHANGELOG.md | 4 ++++ permission_handler/pubspec.yaml | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) 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..ca7e37050 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 From 3e9b599ce4a8b7a17c91d64f36b17615f5ebb8d3 Mon Sep 17 00:00:00 2001 From: Peter WONG Date: Thu, 12 Jan 2023 14:18:11 +0800 Subject: [PATCH 3/3] Update version for Apple plugin: --- permission_handler/pubspec.yaml | 2 +- permission_handler_apple/pubspec.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/permission_handler/pubspec.yaml b/permission_handler/pubspec.yaml index ca7e37050..455017406 100644 --- a/permission_handler/pubspec.yaml +++ b/permission_handler/pubspec.yaml @@ -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/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: