addNSLocation method
Adds NSLocationWhenInUseUsageDescription to Info.plist.
Implementation
String addNSLocation() {
try {
final file = File(_plistPath);
final content = file.readAsStringSync();
if (content.contains('<key>NSLocationWhenInUseUsageDescription</key>')) {
return '⚠️ Info.plist — NSLocationWhenInUseUsageDescription already exists, skipped';
}
const toInsert =
'\t<key>NSLocationWhenInUseUsageDescription</key>\n'
'\t<string>This app requires location access to show maps</string>\n';
final updated = _insertBeforeLastDict(content, toInsert);
if (updated == null) {
return '❌ Could not find </dict> in Info.plist';
}
file.writeAsStringSync(updated);
return '✅ Updated Info.plist — added NSLocationWhenInUseUsageDescription';
} catch (e) {
return '❌ Failed to update Info.plist: $e\n'
'Please open an issue: https://github.com/MohsenBahaj/flutter_ios_capabilities_setup/issues';
}
}