updateDeploymentTarget method

String updateDeploymentTarget()

Raises IPHONEOS_DEPLOYMENT_TARGET to 15.0 in all build configurations where it is currently set below that value.

Implementation

String updateDeploymentTarget() {
  try {
    final file = File(_pbxprojPath);
    var content = file.readAsStringSync();

    final pattern = RegExp(r'IPHONEOS_DEPLOYMENT_TARGET = ([^;]+);');
    final matches = pattern.allMatches(content).toList();

    if (matches.isEmpty) {
      return '⚠️  project.pbxproj — IPHONEOS_DEPLOYMENT_TARGET not found, skipped';
    }

    final anyBelow15 = matches.any((m) {
      final v = double.tryParse(m.group(1)!.trim());
      return v != null && v < 15.0;
    });

    if (!anyBelow15) {
      return '⚠️  project.pbxproj — iOS deployment target already 15.0+, skipped';
    }

    content = content.replaceAllMapped(pattern, (m) {
      final v = double.tryParse(m.group(1)!.trim());
      return (v != null && v < 15.0)
          ? 'IPHONEOS_DEPLOYMENT_TARGET = 15.0;'
          : m.group(0)!;
    });

    file.writeAsStringSync(content);
    return '✅ Updated project.pbxproj — iOS deployment target set to 15.0';
  } catch (e) {
    return '❌ Failed to update deployment target: $e\n'
        'Please open an issue: https://github.com/MohsenBahaj/flutter_ios_capabilities_setup/issues';
  }
}