Titanium iPhone以共享首选项存储变量值

时间:2013-08-21 10:08:21

标签: javascript iphone titanium titanium-mobile

我是钛和iPhone开发的新手,我想知道如何在共享偏好中存储变量值并在另一个js上获取该值?

2 个答案:

答案 0 :(得分:4)

演示使用Titanium App Properties module

的简单示例

我在service.js中设置service_running的布尔值并在app.js中验证

<强> app.js

var isRunning = Ti.App.Properties.getBool("service_running", false);

if (isRunning) 
    Ti.API.info('service is running');
else 
    Ti.API.info('service is not running');

service.js

Ti.App.Properties.setBool("service_running", true);

答案 1 :(得分:2)

应用程序属性模块用于在属性/值对中存储与应用程序相关的数据,这些数据会持续超出应用程序会话和设备电源周期。

实施例

Store a property
Store a string property.

Ti.App.Properties.setString('givenName', 'Paul');
Ti.API.info('The value of the givenName property is: ' + Ti.App.Properties.getString('givenName'));

More.