Phonegap application preference plugin
By David Ferrell (AppGiraffe) / Tue Topholm / Sugee
Copy the .h and .m file to the Plugins directory in your project. Copy the .js file to your www directory and reference it from your html file(s).
The plugin creates the object window.plugins.applicationPreferences
with two methods get(name, success, fail)
and
set(name, value, success, fail)
. name
is the name of the setting you want, value
is the value of the setting you want to set.
success
and fail
are callback functions. Success is passed the settings value as a string.
A full get example could be:
appgiraffe.plugins.applicationPreferences.get('name_identifier', function(result) {
alert("We got a setting: " + result);
}, function(error) {
alert("Failed to retrieve a setting: " + error);
}
);
A full set example could be:
window.plugins.applicationPreferences.set('name_identifier','homer' function() {
alert("It is saved");
}, function(error) {
alert("Failed to retrieve a setting: " + error);
}
);
NOTE: The preference must exist in a settings bundle and Root.plist in your project. See http://developer.apple.com/library/ios/#DOCUMENTATION/Cocoa/Conceptual/UserDefaults/Preferences/Preferences.html for further details.
- Open Cordovo.plist file in Xcode
- To the plugins Dictionary add a new String item
- Name and value of the item would be "applicationPreferences"
The latest release version is available on GitHub If you have a patch, fork my repo and send me a pull request. Submit bug reports on GitHub, please.
The MIT License
Copyright (c) 2013 David Ferrell (AppGiraffe) / Tue Topholm / Sugee
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.