(我是一名原生 iPhone 开发者 - Phonegap/Cordova 新手)
对于某些设置或首选项,我们在 native iOS 中使用 NSUserDefaults。使用 webviews 和phonegap 时有等效的吗? 提前致谢。
最佳答案
有一个Application preferences Cordova plugin .
Usage :
function ok (value) {}
function fail (error) {}
var prefs = plugins.appPreferences;
// cordova interface
// store key => value pair
prefs.store (ok, fail, 'key', 'value');
// store key => value pair in dict (see notes)
prefs.store (ok, fail, 'dict', 'key', 'value');
// fetch value by key (value will be delivered through "ok" callback)
prefs.fetch (ok, fail, 'key');
// fetch value by key from dict (see notes)
prefs.fetch (ok, fail, 'dict', 'key');
// remove value by key
prefs.remove (ok, fail, 'key');
// show application preferences
prefs.show (ok, fail);
// instead of cordova interface you can use promise interface
// you'll receive promise when you won't pass function reference
// as first and second parameter
// fetch the value for a key using promise
prefs.fetch ('key').then (ok, fail);
// support for iOS suites (untested)
var suitePrefs = prefs.iosSuite ("suiteName");
suitePrefs.fetch (...);
suitePrefs.store (...);
关于iphone - Phonegap 中的 NSUserDefaults,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12800844/