Skip to content

Instantly share code, notes, and snippets.

@DURK
Created February 17, 2015 13:37
Show Gist options
  • Save DURK/87e7a7ec832bcc364ada to your computer and use it in GitHub Desktop.
Save DURK/87e7a7ec832bcc364ada to your computer and use it in GitHub Desktop.
Cordova-hook to disable webstorage backups in iCloud
#!/usr/bin/env node
/**
* After prepare, the iOS BackupWebStorage preference will be disabled.
* We already disabled it in www/config.xml, but there's an issue in Cordova (or a plugin?) that makes it ignore this.
* See: https://issues.apache.org/jira/browse/CB-8327
*/
var fs = require('fs');
var path = require('path');
var cordova_util = require('cordova-lib/src/cordova/util');
var projectRoot = cordova_util.isCordova(process.cwd());
var projectXml = cordova_util.projectConfig(projectRoot);
var ConfigParser = require('cordova-lib/src/ConfigParser/ConfigParser');
var projectConfig = new ConfigParser(projectXml);
var projectName = projectConfig.name();
function replace_string_in_file(filename, to_replace, replace_with) {
var data = fs.readFileSync(filename, 'utf8');
var result = data.replace(new RegExp(to_replace, "g"), replace_with);
fs.writeFileSync(filename, result, 'utf8');
console.log("replace %s with %s in %s", to_replace, replace_with, filename);
}
var iosPlatformsConfig = path.resolve(__dirname, '../../platforms/ios/'+projectName+'/config.xml');
replace_string_in_file(iosPlatformsConfig, '"cloud"', '"none"');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment