// Author: fengshengxiong
// Date: 2024/6/26
// Description: iOS跟踪授权工具

import 'dart:io';

import 'package:app_tracking_transparency/app_tracking_transparency.dart';
import 'package:get/get.dart';
import 'package:tone_snap/components/dialog/remind_dialog.dart';
import 'package:tone_snap/utils/log_util.dart';

class TrackingAuthorizationUtil {
  /// 请求跟踪授权
  static Future<void> requestTrackingAuthorization() async {
    if (Platform.isIOS) {
      final TrackingStatus status = await AppTrackingTransparency.trackingAuthorizationStatus;
      if (status == TrackingStatus.notDetermined) {
        // await _showCustomTrackingDialog();
        // await Future.delayed(const Duration(milliseconds: 200));
        final TrackingStatus status = await AppTrackingTransparency.requestTrackingAuthorization();
        LogUtil.d('跟踪授权状态: $status');
      }
    }
  }

  static Future<void> _showCustomTrackingDialog() async {
    await Get.dialog(
      barrierDismissible: false,
      RemindDialog(
        title: 'Dear User',
        content: 'We need your permission to access the advertising identifier to provide better ad services.',
        confirmText: 'Continue',
        showCancelBtn: false,
        confirmOnTap: Get.back,
      ),
    );
  }
}
