Cordova Phonegap IOS App Settings.Bundle Possible?

前端 未结 1 1136
刺人心
刺人心 2020-12-31 19:39

So I\'m new to mobile development but I\'m close to finishing up my first IOS application using HTML/CSS/JS and Cordova PhoneGap 3. I am trying to allow the user to provide

1条回答
  •  时光取名叫无心
    2020-12-31 20:11

    To create a Settings bundle that will work without having to muck in platforms/ios/, create a local plugin in your project.

    ./src/ios/plugin.xml

    
    
    
    
        Application Settings
        My Application's Default Settings
        Proprietary
        preferences, settings, default
        https://github.com/
    
            
            
        
    
    

    In Xcode, open ./src/ios, and create a new Settings.bundle

    ./src/ios/Settings.bundle/Root.plist

    
    
    
    
    
        PreferenceSpecifiers
        
            
                Title
                API Server
                Type
                PSGroupSpecifier
            
            
                AutocapitalizationType
                None
                AutocorrectionType
                No
                DefaultValue
                https://api.example.com
                IsSecure
                
                Key
                name_preference
                KeyboardType
                Alphabet
                Type
                PSTextFieldSpecifier
            
        
        StringsTable
        Root
    
    
    

    At the root of your project, run cordova plugin add ./src/ios. It will say Installing "com.dataonline.dolores.settings" for ios.

    Use me.apla.cordova.app-preferences to load those settings from Javascript.

    ./src/client/preferences.js

    function ApplicationPreferences(){
        var _this = this;
        this.server = window.location.origin;
        document.addEventListener('deviceready', function(){
            function loaded(server){_this.server = server;}
            plugins.appPreferences.fetch(loaded, function(){}, 'api_server');
        });
    };
    
    applicationPreferences = new ApplicationPreferences();
    // Later..
    $.get(applicationPreferences.server + "/api/data");
    

    Edit Switched from two s to one

    0 讨论(0)
提交回复
热议问题