parse method

  1. @override
Future<AppPackage> parse(
  1. File file
)

Implementation

@override
Future<AppPackage> parse(File file) async {
  final ipaBytes = file.readAsBytesSync();
  final archive = ZipDecoder().decodeBytes(ipaBytes);

  String xmlString = '';
  for (final item in archive) {
    if (item.isFile && item.name.endsWith('.app/Info.plist')) {
      final data = item.content as List<int>;
      xmlString = utf8.decode(data);
      break;
    }
  }

  XmlDocument xmlDoc = XmlDocument.parse(xmlString);
  XmlElement elPlist = xmlDoc.getElement('plist')!;
  XmlElement elDict = elPlist.getElement('dict')!;

  List<String> keys = elDict.childElements
      .where((e) => e.name.local == 'key')
      .map((e) => e.text)
      .toList();
  List<dynamic> values = elDict.childElements
      .where((e) => e.name.local != 'key')
      .map(_handleElem)
      .toList();
  Map dict = Map.fromIterables(keys, values);

  AppPackage appPackage = AppPackage(
    platform: 'ios',
    identifier: dict['CFBundleIdentifier'],
    name: dict['CFBundleDisplayName'],
    version: dict['CFBundleShortVersionString'],
    buildNumber: int.parse(dict['CFBundleVersion']),
  );
  return appPackage;
}