iphone - Phonegap 中的 NSUserDefaults

标签 iphone xcode cordova nsuserdefaults

(我是一名原生 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/

相关文章:

iphone - 如何在cocos2d-iphone中的CCLayer或CCScene中添加UITextView

iphone - OpenAL 和 Popping 工件

iphone - 以编程方式更改 iPhone 背景

javascript - 在 node-sass@0.9.6 安装脚本 'node build.js' 失败

HTML 选择 "Done"标签未在 Ionic for iOS 上显示

iOS 崩溃 : libswiftAssetsLibrary. dylib 未加载

ios - 为什么我的 CoreData 实体对象是未知的?

xcode - Swift 正确的自动释放池

swift - 在 iCloud 设备之间同步通知

javascript - 与桌面浏览器兼容的 HTML5 移动框架