parseInfoPlist static method

PlatformConfig? parseInfoPlist(
  1. File infoPlistFile
)

Parse Info.plist file

Implementation

static PlatformConfig? parseInfoPlist(File infoPlistFile) {
  try {
    final content = infoPlistFile.readAsStringSync();
    final plist = PlistParser().parse(content);

    var bundleIdentifier = plist['CFBundleIdentifier'] as String?;
    final urlTypes = plist['CFBundleURLTypes'] as List?;
    final urlSchemes = <String>[];

    // Resolve Xcode build variables like $(PRODUCT_BUNDLE_IDENTIFIER)
    if (bundleIdentifier != null && _isXcodeVariable(bundleIdentifier)) {
      final resolvedId = _resolveXcodeVariable(
        bundleIdentifier,
        infoPlistFile.parent.path,
      );
      if (resolvedId != null) {
        bundleIdentifier = resolvedId;
      }
    }

    if (urlTypes != null) {
      for (final urlType in urlTypes) {
        if (urlType is Map) {
          final schemes = urlType['CFBundleURLSchemes'] as List?;
          if (schemes != null) {
            for (final scheme in schemes) {
              if (scheme is String) {
                urlSchemes.add(scheme);
              }
            }
          }
        }
      }
    }

    // Extract team ID from Xcode project file
    String? teamId;
    if (bundleIdentifier != null) {
      // Try to find project.pbxproj and extract DEVELOPMENT_TEAM
      teamId = _extractTeamIdFromProject(infoPlistFile.parent.path);
    }

    return PlatformConfig(
      projectType: ProjectType.ios,
      bundleIdentifier: bundleIdentifier,
      urlSchemes: urlSchemes,
      iosUrlSchemes: urlSchemes,
      teamId: teamId,
    );
  } catch (e) {
    return null;
  }
}