Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix App Tracking Transparency request may fail to show. #967

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
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/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions permission_handler/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion permission_handler_apple/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down