Each time I run my App, the Notification dialog comes way before the App tracking authorization. I’d like the user to see at first the App tracking Transparency dialog before the Notification dialog. I tried requesting the tracking authorization await AppTrackingTransparency.requestTrackingAuthorization();
before the runApp()
or after it and above the Push Notification request await PushNotificationService().setupInteractedMessage();
and added the key in info.plist, however, the result is the same, notification dialog comes first. Kindly check my code.
int? initScreen;
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
// await Firebase.initializeApp();
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
);
// runApp(MyApp());
SharedPreferences preferences = await SharedPreferences.getInstance();
initScreen = await preferences.getInt('initScreen');
await preferences.setInt('initScreen', 1);
// MobileAds.instance.initialize();
runApp(MyApp());
//await AppTracking
// final status = await AppTrackingTransparency.requestTrackingAuthorization();
await AppTrackingTransparency.requestTrackingAuthorization();
await PushNotificationService().setupInteractedMessage();
MobileAds.instance.initialize();
RemoteMessage? initialMessage =
await FirebaseMessaging.instance.getInitialMessage();
if (initialMessage != null) {
// App received a notification when it was killed
}
}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
// final TrackingStatus status;
//
// MyApp({required this.status});
static FirebaseAnalytics analytics = FirebaseAnalytics.instance;
static FirebaseAnalyticsObserver observer =
new FirebaseAnalyticsObserver(analytics: analytics);
@override
Widget build(BuildContext context) {
// String statusText;
// switch (status) {
// case TrackingStatus.authorized:
// statusText = 'Tracking Status Authorized';
// break;
// case TrackingStatus.denied:
// statusText = 'Tracking Status Denied';
// break;
// case TrackingStatus.notDetermined:
// statusText = 'Tracking Status Not Determined';
// break;
// case TrackingStatus.notSupported:
// statusText = 'Tracking Status Not Supported';
// break;
// case TrackingStatus.restricted:
// statusText = 'Tracking Status Restricted';
// break;
// default:
// statusText = 'You should not see this...';
// break;
// }
return GetMaterialApp(
debugShowCheckedModeBanner: false,
title: 'Culture Islamique',
theme: ThemeData(
primarySwatch: Colors.blue,
),
// home:
initialRoute: initScreen == 0 || initScreen == null ? 'onboard' : 'home',
routes: {
'home': (context) => navbar(analytics: analytics, observer: observer),
'onboard': (context) => onboardingHomePage(),
},
);
}
}```
[![enter image description here][1]][1]
[1]: https://i.stack.imgur.com/R3eHd.png
2
Answers
IOS does not allow to display multiple native dialogs.
Here is my workaround inspired by the example provided by the app-tracking-transparency package on pub.dev
First, I removed the
await AppTrackingTransparency.requestTrackingAuthorization();
from main instead call it in the HomeScreen (navbar).Next, in the HomeScreen call this function
initPlugin()
ininitState()
see the code.After that, Once you run your App, the notification permission will come first, followed by the explanatory dialog then the app tracking authorization permission will be requested. This will prevent your app from being rejected from the App Store.
For more info check the [example][1]
[1]: https://pub.dev/packages/app_tracking_transparency/example on pub.dev
To ensure that the tracking transparency permission dialog appears before the notification permission dialog in your Flutter iOS app, you need to rearrange your code to request the tracking transparency permission before initializing Firebase and setting up push notifications. Here’s how you can modify your
main()
function:In this modified code:
requestTrackingPermission()
function, which requests tracking transparency permission using theflutter_app_tracking_transparency
package.setupPushNotifications()
function handles the setup for push notifications using Firebase Messaging.handleInitialMessage()
function handles the initial message when the app is launched from a notification.main()
function before initializing Firebase, setting up push notifications, and running the app. This ensures that the tracking transparency permission dialog appears before any other dialogs related to permissions or services.