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 if an other is already shown or in Release #26

Open ghost opened 2 years ago

ghost commented 2 years ago

AppTrackingTransparency.trackingAuthorizationStatus always return notDetermined if an other popup like notification permissions is visible.

[✓] Flutter (Channel stable, 2.10.3, on macOS 12.2.1 21D62 darwin-arm, locale fr-FR)
    • Flutter version 2.10.3 at /Users/***********/fvm/versions/2.10.3
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 7e9793dee1 (10 days ago), 2022-03-02 11:23:12 -0600
    • Engine revision bd539267b4
    • Dart version 2.16.1
    • DevTools version 2.9.2

[✓] Android toolchain - develop for Android devices (Android SDK version 32.1.0-rc1)
    • Android SDK at /Users/***********/Library/Android/Sdk
    • Platform android-32, build-tools 32.1.0-rc1
    • ANDROID_HOME = /Users/***********/Library/Android/Sdk
    • Java binary at: /Users/***********/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/211.7628.21.2111.8193401/Android Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.11+0-b60-7772763)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 13.2.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • CocoaPods version 1.11.2

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2021.1)
    • Android Studio at /Users/***********/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/211.7628.21.2111.8193401/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.11+0-b60-7772763)
ghost commented 2 years ago

In addition popup seems not appear in production (release mode).

I've wrapped my MaterialApp with the following code :

import 'dart:io';

import 'package:app_tracking_transparency/app_tracking_transparency.dart';
import 'package:firebase_analytics/firebase_analytics.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:visilab/services/logger.dart';

// Should we await for ATT before displaying app ? I notice that it took some times...
class MyAppTrackingTransparency extends StatefulWidget {
  final Widget child;

  const MyAppTrackingTransparency({final Key? key, required this.child}) : super(key: key);

  @override
  State<MyAppTrackingTransparency> createState() => _MyAppTrackingTransparency();
}

class _MyAppTrackingTransparency extends State<MyAppTrackingTransparency> {
  @override
  void initState() {
    super.initState();

    if (Platform.isIOS) {
      // Can't show the dialog in initState, delaying initialization
      WidgetsBinding.instance!.addPostFrameCallback((final _) {
         initATT();
      });
    }
  }

  Future<void> initATT() async {
    TrackingStatus status = TrackingStatus.notDetermined;

    try {
      status = await AppTrackingTransparency.trackingAuthorizationStatus;
      //setState(() => _authStatus = '$status');
      // If the system can show an authorization request dialog
      if (status == TrackingStatus.notDetermined) {
        status = await AppTrackingTransparency.requestTrackingAuthorization();
      }
    } catch (err, stack) {
      LoggerCrashlytics.record(exception: err, stack: stack, reason: 'AppTrackingTransparency failed !');
    } finally {
      //setState(() => ready = true);
    }

    if (kDebugMode) print(status);
  }

  @override
  Widget build(final BuildContext context) {
    return widget.child;
  }
}

I need to wrap initATT inside a Future.delayed to let him work in release, in debug popup is well displayed... Seems like I ask ATT 'too fast'...

Future<dynamic>.delayed(const Duration(seconds: 2), initATT);

Can you provide me some information about why this happen and what is the best way to implement ATT in Flutter app (where ?) :/

yazanAboAlaynin commented 2 years ago

it happened to me also and it is not showing in release. did you find the problem?

ahndwon commented 2 years ago

Also happening to me. My app update got rejected on App Store. Need a fix asap.

ghost commented 2 years ago

I put a Future.delayed(Duration(seconds: 2)); before call ATT. App was approuved, but it is dirty !

yazanAboAlaynin commented 2 years ago

in my case the permission was showing but they rejecting the app, i solved the problem by changing the privacy of the app , go to app privacy and in data types section click edit and select Identifiers (Device ID) and set this one as used for tracking purposes. and make sure that this is the only one selected as used for tracking. and i hope it will work with you if it is the same problem.

GoldenSoju commented 1 year ago

My app also got rejected because of that error.

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.