deniza / app_tracking_transparency

A Flutter plugin to show ios 14+ tracking authorization dialog.
https://pub.dev/packages/app_tracking_transparency/
MIT License
83 stars 28 forks source link

Popup not displayed above IOS 15.4+ #32

Open ThebaultLouis opened 2 years ago

ThebaultLouis commented 2 years ago

I need to request permission to collect data with the app tracking transparency dialog. The dialog shows up in my simulator (iphone 13 ios 15.2) but not on real devices (iphone 13 on 15.4 and iphone 13 on 15.5)

I implemented the package with the following code

 @override
  void initState() {
    super.initState();

    WidgetsFlutterBinding.ensureInitialized()
        .addPostFrameCallback((_) => AppTrackingTransparency.requestTrackingAuthorization());
  }
juri180 commented 2 years ago

Same here. The permission dialog is shown on Simulator with iOS 15.5, but not on a real device with iOS 15.5. On the real device AppTrackingTransparency.requestTrackingAuthorization(); always returns status denied immediately, without showing the dialog.

For test purposes I disabled all my other dialogs and added a delay to the permission dialog – no luck. I also tried to implement it myself and tried all the different suggestions of this Stackoverflow thread, but couldn't fix it.

Any help would be highly appreciated. Thank you!

ThebaultLouis commented 2 years ago

What I did was to wait 2 seconds before asking for the permission and I don't know why it worked suddently. Apple accepted my submission after this change

@override
  void initState() {
    super.initState();

    WidgetsFlutterBinding.ensureInitialized()
        .addPostFrameCallback((_) async {
          await Future.delayed(const Duration(milliseconds: 2000));
          await AppTrackingTransparency.requestTrackingAuthorization()
        );
  }
juri180 commented 2 years ago

@ThebaultLouis Thanks for your response. I tried this approach already and it didn't work, but now it does. My second problem was the I wasn't aware of the iOS setting "allow tracking permission requests". On my test device, this setting was set to false, so all request immediately returned denied.

marcellocamara commented 2 years ago

Any fix around it ? @deniza

I don't think wait 2 seconds for a long time will be healthy

FernandoUFS commented 2 years ago

I have the same issue here, and apple isn't approving my application because of that. My device has "allow tracking permission requests" enabled, but nothing I do make it works. I tried delay request, I removed other requests (like notification permissions). The request is just not shown.

deniza commented 2 years ago

Did you tried to call AppTrackingTransparency.trackingAuthorizationStatus? What do you get when you call it?

marcellocamara commented 2 years ago

Did you tried to call AppTrackingTransparency.trackingAuthorizationStatus? What do you get when you call it?

@deniza I don't have an iPhone here to test it, but if you could, will be greatful. On the simulator the issue doesn't appears. I know a serie of big companies that use this package and they are at the mercy of this problem.

To simulate this problem I think it just you ask for the tracking dialog on the first step of your app... Maybe for those who fetch some data first are not going through this issue (talking this because to fix this issue we force wait 2 seconds to call the tracking dialog).

We had publishing problems because of this, and I think the numbers of people will increase.

GoldenSoju commented 1 year ago

My app also got rejected because of that error. I saw that the ATT permission dialog got dismissed because of another permission dialog.

I saw that ATTrackingManager has an async function. And I was hoping I could force wait for the function.

class func requestTrackingAuthorization() async -> ATTrackingManager.AuthorizationStatus

But using an async function in the method channel on iOS-side makes the app crash and I couldn't find a way to solve that. Could be a limitation of the method channel.

FernandoUFS commented 1 year ago

I find that after aprove or deny this permission manually on the iPhone settings the permission request is not shown anymore. Even if I uninstall completely the app and install it again the option I chose before remains checked. I used two other iPhones and the dialog showed up as expected. Maybe the problem isn't the plugin but iOS doing this.

thanglq-teraark commented 1 year ago

My app also got rejected due to this issue. Any update ?

deniza commented 1 year ago

I highly recommend showing an explainer dialog before requesting tracking authorization. Please check the sample project. This is the officially recommended (by google) way which leads far better acceptance rates, hence more ads revenue.

I tested the package on various ios versions (15.x and upcoming 16 beta). Everything seems to work fine. (I am using explainer dialog approach)

b099l3 commented 1 year ago

I had a similar problem, showing on the simulator not on any iOS 15 device.

Solved it by checking the global setting in: Settings App > Privacy > Tracking > Set to enabled

I dont remember setting this at all on my device

After that the popup started showing, didn't need todo any delays

PieterWvdV commented 1 year ago

I highly recommend showing an explainer dialog before requesting tracking authorization. Please check the sample project. This is the officially recommended (by google) way which leads far better acceptance rates, hence more ads revenue.

I tested the package on various ios versions (15.x and upcoming 16 beta). Everything seems to work fine. (I am using explainer dialog approach)

I Already have another few dialogs which I am awaiting before I show the ATT dialog. Still it is not displaying. I have tried the delays with no success

sparkmobi commented 1 year ago

Any Updates? i am getting the same apple rejection

bypass112 commented 1 year ago

Hi please make sure you have "Allow Apps to Request to Track" enabled on device and make sure the app is properly mounted on the native side. I would recommend requesting the dialog in an initState of a screen, maybe the first one. https://github.com/zoontek/react-native-permissions/issues/648#issuecomment-928077147 this explains more about it

KKimj commented 1 year ago

Hello Here is simple solution to handle this issue.

if (authorizationStatus == TrackingStatus.notDetermined) {...} -> while (authorizationStatus == TrackingStatus.notDetermined) {...}

Avoid infinite loop, Add int timeoutCount variable.

After

TrackingStatus authorizationStatus =
        await AppTrackingTransparency.trackingAuthorizationStatus;
    int timeoutCount = 0;
    while (authorizationStatus == TrackingStatus.notDetermined &&
        timeoutCount < 10) { // Adjust yourself.. maybe up to ~50
      authorizationStatus =
          await AppTrackingTransparency.requestTrackingAuthorization();
      await Future.delayed(const Duration(milliseconds: 200));
      timeoutCount++;
    }

Before

TrackingStatus authorizationStatus =
        await AppTrackingTransparency.trackingAuthorizationStatus;
    if (authorizationStatus == TrackingStatus.notDetermined) {
      authorizationStatus =
          await AppTrackingTransparency.requestTrackingAuthorization();
    }

This is the demonstration screenshot video.

https://user-images.githubusercontent.com/40026920/210933941-572f819d-9b5b-4588-84f1-1c582301f8f2.mov

Thanks!

mkbsugita commented 1 year ago

iOS 16.4 can't open. iOS 16.1.1 can open Why? But I build on Xcode 14.1. Xcode version is necessary?

README says using XCode 12 and run your app on an ios 14 device. only.

Zaveri21 commented 1 year ago

@luminkhant i was facing this same issue. I added bellow code in appDelegate.swift file and Authorisation default alert showing in iOS 16+

func applicationDidBecomeActive(_ application: UIApplication) {
    if #available(iOS 14, *) {
        ATTrackingManager.requestTrackingAuthorization { status in
            switch status {
            case .authorized:
                // Tracking authorization dialog was shown
                // and we are authorized
                print("Authorized")
            case .denied:
                // Tracking authorization dialog was
                // shown and permission is denied
                print("Denied")
            case .notDetermined:
                // Tracking authorization dialog has not been shown
                print("Not Determined")
            case .restricted:
                print("Restricted")
            @unknown default:
                print("Unknown")
            }
        }
    }
}
mkbsugita commented 1 year ago

@Zaveri21 Thank you for your information.

I hope you to make pull-request for it. https://github.com/deniza/app_tracking_transparency/blob/master/ios/Classes/SwiftAppTrackingTransparencyPlugin.swift

yanqiuLove commented 11 months ago

我的项目是Flutter创建的,iOS端语言使用的是OC,针对该问题我的解决方案如下: 在AppDelegate.m文件中加入以下代码:

import <AppTrackingTransparency/AppTrackingTransparency.h>

import <AdSupport/ASIdentifierManager.h>

- (void)applicationDidBecomeActive:(UIApplication *)application { if (@available(iOS 14, *)) { // iOS14及以上版本先请求权限 [ATTrackingManager requestTrackingAuthorizationWithCompletionHandler:^(ATTrackingManagerAuthorizationStatus status) { // 获取到权限后使用老方法获取idfa if (status == ATTrackingManagerAuthorizationStatusAuthorized) { NSString *idfa = [[ASIdentifierManager sharedManager].advertisingIdentifier UUIDString]; NSLog(@"%@",idfa); } else { NSLog(@"请在设置-隐私-跟踪中允许App请求跟踪"); } }]; } else { // iOS14以下版本使用老方法 // 判断在设置-隐私里是否打开了广告跟踪 if ([[ASIdentifierManager sharedManager] isAdvertisingTrackingEnabled]) { NSString *idfa = [[ASIdentifierManager sharedManager].advertisingIdentifier UUIDString]; NSLog(@"%@",idfa); } else { NSLog(@"请在设置-隐私-广告中打开广告跟踪功能"); } } }