import 'dart:io';

import 'package:app_tracking_transparency/app_tracking_transparency.dart';
import 'package:device_info_plus/device_info_plus.dart';

import 'atmob_platform_info.dart';

class PlatformIosInfo {
  static Future<void> init() async {
    if (Platform.isIOS) {
      DeviceInfoPlugin deviceInfoPlugin = DeviceInfoPlugin();
      IosDeviceInfo iosInfo = await deviceInfoPlugin.iosInfo;
      atmobPlatformInfo
          .setModel(iosInfo.model)
          .setIdfv(iosInfo.identifierForVendor);

      final TrackingStatus status =
      await AppTrackingTransparency.trackingAuthorizationStatus;
      if (status == TrackingStatus.notDetermined) {
        final TrackingStatus newStatus =
        await AppTrackingTransparency.requestTrackingAuthorization();
        if (newStatus == TrackingStatus.authorized) {
          atmobPlatformInfo.setIdfa(
              await AppTrackingTransparency.getAdvertisingIdentifier());
        }
      } else if (status == TrackingStatus.authorized) {
        atmobPlatformInfo
            .setIdfa(await AppTrackingTransparency.getAdvertisingIdentifier());
      }
    }
  }
}
