getIosUniqueId static method

Future<String?> getIosUniqueId()

获取 iOS 唯一标识 优先读取 KeyChain 缓存,失败时依次尝试 IDFA、IDFV,最后生成本地 UUID 保存

Implementation

static Future<String?> getIosUniqueId() async {
  if (!Platform.isIOS) return null;

  final cachedId = await _readIosDeviceIdFromKeychain();
  if (_isValidIdentifier(cachedId)) {
    return cachedId;
  }
  final generatedId = _uuid.v4();
  await _writeIosDeviceIdToKeychain(generatedId);
  return generatedId;
  // final idfa = await deviceIdentifier.getAdvertisingIdForiOS();
  // if (_isValidIdentifier(idfa)) {
  //   await _writeIosDeviceIdToKeychain(idfa!);
  //   return idfa;
  // }

  // final idfv = await deviceIdentifier.getAppleIDFV();
  // if (_isValidIdentifier(idfv)) {
  //   await _writeIosDeviceIdToKeychain(idfv!);
  //   return idfv;
  // }
}