deniza / app_tracking_transparency

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

Having issue how to add app tracking transparency to my app #10

Closed 7oda187 closed 1 year ago

7oda187 commented 3 years ago

Hello Team,

Kindly need your support on how can add app_tracking_transparency to my app. As i'm using flutter for my project. everything is working normally but having difficulty with this one.

Can you please guide me on how to implement this in my app?

Attached my main.dart code below:

`import 'dart:io' show HttpClient;

import 'package:flutter/gestures.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:pedantic/pedantic.dart'; import 'package:provider/provider.dart'; import 'package:responsive_builder/responsive_builder.dart';

import 'app.dart'; import 'common/config.dart'; import 'common/constants.dart'; import 'common/firebase_services.dart'; import 'common/tools.dart'; import 'env.dart'; // import 'frameworks/vendor_admin/vendor_admin_app.dart';

Future main() async { WidgetsFlutterBinding.ensureInitialized(); Configurations().setConfigurationValues(environment);

GestureBinding.instance.resamplingEnabled = true;

Provider.debugCheckInvalidValueType = null; printLog('[main] ============== main.dart START ==============');

if (!kIsWeb) { /// enable network traffic logging HttpClient.enableTimelineLogging = true;

unawaited(SystemChrome.setPreferredOrientations(
    [DeviceOrientation.portraitUp, DeviceOrientation.portraitDown]));
SystemChrome.setSystemUIOverlayStyle(
  SystemUiOverlayStyle.dark.copyWith(statusBarColor: Colors.transparent),
);

}

// Initialize Firebase due to version 0.5.0+ requires to if (!isWindow) { await GmsTools().checkGmsAvailability(); await FirebaseServices().init();

if (FirebaseServices().isAvailable) {
  // await Configurations().loadRemoteConfig();
  printLog('[main] Initialize Firebase successfully');
}

}

// if (serverConfig['type'] == 'vendorAdmin') { // return runApp(const VendorAdminApp()); // }

ResponsiveSizingConfig.instance.setCustomBreakpoints( const ScreenBreakpoints(desktop: 900, tablet: 600, watch: 100)); runApp(App()); } `

Appreciate your kind support.

untp commented 3 years ago

There are many ways to use this package. You can show dialog after app launch, after onboarding finished, or before first ad load. You can also show an explainer dialog before system dialog. Check README and example for integrating this package.

Also, I see you are using if (!kIsWeb), therefore you are targeting both web and iOS. So you need to wrap this package's method calls with !kIsWeb like:

if (!kIsWeb) {
  await AppTrackingTransparency.requestTrackingAuthorization();
}

That's it. I don't know which problem you are getting. Can you explain in more detail the difficulties you are having?

7oda187 commented 3 years ago

There are many ways to use this package. You can show dialog after app launch, after onboarding finished, or before first ad load. You can also show an explainer dialog before system dialog. Check README and example for integrating this package.

Also, I see you are using if (!kIsWeb), therefore you are targeting both web and iOS. So you need to wrap this package's method calls with !kIsWeb like:

if (!kIsWeb) {
  await AppTrackingTransparency.requestTrackingAuthorization();
}

That's it. I don't know which problem you are getting. Can you explain in more detail the difficulties you are having?

Dear Untp,

Thank you for your reply.

Actually i want the message appear to the user after onboarding finished,

Can you help me with the code writing for it.

untp commented 3 years ago

It depends on what package you are using for onboarding. For example if you use fancy_on_boarding, you can show the dialog when the user taps the done button:

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: FancyOnBoarding(
        ...
        onDoneButtonPressed: () {
          try {
            // If the system can show an authorization request dialog
            if (await AppTrackingTransparency.trackingAuthorizationStatus ==
                TrackingStatus.notDetermined) {
              // Show a custom explainer dialog before the system dialog
              if (await showCustomTrackingDialog(context)) {
                // Wait for dialog popping animation
                await Future.delayed(const Duration(milliseconds: 200));
                // Request system's tracking authorization dialog
                await AppTrackingTransparency.requestTrackingAuthorization();
              }
            }
          } on PlatformException {
            // Unexpected exception was thrown
          }
          Navigator.of(context).pushReplacementNamed('/main');
        }
      ),
    );
  }

For introduction_screen, you can add the dialog request to onDone callback. Almost all onboarding packages, provide an onDone callback. If you are using a custom solution for onboarding, you can add the dialog request before navigating to the main page.