1

I'm trying to implement App Tracking Transparency on my Flutter app with the package app_tracking_transparency 2.0.2+4 for iOS.

I'm on Flutter 3.0.5

Before the ATT dialog, I want show a custom dialog but my app show only the ATT dialog without my custom dialog before.

This is my code:

class _MyAppState extends State<MyApp> {
  String _authStatus = 'Unknown';

  Completer<ThemeData>? themeDataCompleter;
  SharedPreferences? SharedPreferences;

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

  Future<void> initPlugin() async {
    final TrackingStatus status =
    await AppTrackingTransparency.trackingAuthorizationStatus;
    setState(() => _authStatus = '$status');
    // If the system can show an authorization request dialog
    if (status == TrackingStatus.notDetermined) {
      // Show a custom explainer dialog before the system dialog
      await showCustomTrackingDialog(context);
      // Wait for dialog popping animation
      await Future.delayed(const Duration(milliseconds: 2000), (){});
      // Request system's tracking authorization dialog
      final TrackingStatus status =
      await AppTrackingTransparency.requestTrackingAuthorization();
      setState(() => _authStatus = '$status');
    }

    final uuid = await AppTrackingTransparency.getAdvertisingIdentifier();
    print("UUID: $uuid");
  }

  Future<void> showCustomTrackingDialog(BuildContext context) async =>
      await showDialog<void>(
        context: context,
        builder: (context) =>
            AlertDialog(
              title: const Text('Dear User'),
              content: const Text(
                'We care about your privacy and data security. We keep this app free by showing ads. '
                    'Can we continue to use your data to tailor ads for you?\n\nYou can change your choice anytime in the app settings. '
                    'Our partners will collect data and use a unique identifier on your device to show you ads.',
              ),
              actions: [
                TextButton(
                  onPressed: () => Navigator.pop(context),
                  child: const Text('Continue'),
                ),
              ],
            ),
      );

What is wrong? I check the dev's example un pub.dev page but it seems the same code.

Thank you

David S.
  • 671
  • 3
  • 13

1 Answers1

0

I think maybe you should lose the

async =>
      await showDialog<void>(

from your showCustomTrackingDialog method.

Here is my working example, but with the permission_hanndler package. It's basically the same thing, I'm just calling another method.

Future<void> askAATPermission(BuildContext context) async {
    await showCustomTrackingDialog(context);
    await Future.delayed(Duration(milliseconds: 300));

    var status = await Permission.appTrackingTransparency.status;
    if (status.isDenied) {
      // We didn't ask for permission yet or the permission has been denied before but not permanently.
      PermissionStatus permission =
      await Permission.appTrackingTransparency.request();

      if (permission.isGranted) {
        [...]
      } else {
        [...]
      }
    }
  }

Thanks for asking the question and giving me the idea to show a dialog first, then delay and then ask for the AAT permission.

Hope it helped.

Mad World
  • 129
  • 2
  • 8