Add entry to iOS .plist file via Cordova config.xml

后端 未结 15 1526
日久生厌
日久生厌 2020-11-28 21:41

I am new to the Cordova CLI.

I need to perform the following steps programmatically via Cordova.

  1. In the project .plist add a new row
  2. Enter th
15条回答
  •  误落风尘
    2020-11-28 22:24

    @TachyonVortex solution seems to be the best option but was crashing down in my case. The issue was caused by an empty NSMainNibFile field that is not right converted by the plist NPM package. In the .plist file

        NSMainNibFile
        
        NSMainNibFile~ipad
        
    

    is converted to:

        NSMainNibFile
        NSMainNibFile~ipad
    

    I fixed it with by adding to the script:

        obj.NSMainNibFile = '';
        obj['NSMainNibFile~ipad'] = '';
    

    The script finally looks like (scripts/my-hook.js):

    var fs    = require('fs');     // nodejs.org/api/fs.html
    var plist = require('plist');  // www.npmjs.com/package/plist
    
    var FILEPATH = 'platforms/ios/***/***-Info.plist';
    
    module.exports = function (context) {
    
        var xml = fs.readFileSync(FILEPATH, 'utf8');
        var obj = plist.parse(xml);
    
        obj.GDLibraryMode = 'GDEnterpriseSimulation';
        obj.NSMainNibFile = '';
        obj['NSMainNibFile~ipad'] = '';
    
        xml = plist.build(obj);
        fs.writeFileSync(FILEPATH, xml, { encoding: 'utf8' });
    
    };
    

    and config.xml:

    
        
    
    

提交回复
热议问题