我可以在哪个文件中放置一个脚本来清除 Titanium 应用程序的缓存
in which file can I put a script to erase the caches of the Titanium application
我写了一个脚本,允许您删除应用程序缓存中的 属性,但是我只需要在安装应用程序时 运行 这个脚本一次。
有人有想法,谢谢
var executed = 0;
if(executed === 0){
Ti.App.Properties.removeProperty("My_Property");
executed++;
}
您可以在应用程序会话中保留一些价值的唯一方法是 Ti.App.Properties 或 sql 数据库。因此,您可以通过以下两种方式进行操作:
解决方法一:用另一个属性知道你删除了想要的属性.
// for first time installation, the default value (or 2nd parameter) will be false as you have not deleted the property yet
var isDeleted = Ti.App.Properties.getBool('My_Property_Deleted', false);
if (isDeleted) {
Ti.App.Properties.removeProperty("My_Property");
// since you have deleted it, now set it to true so this 'if' block doesn't runs on any next app session
Ti.App.Properties.setBool('My_Property_Deleted', true);
} else {
// you have already deleted the property, 'if' block won't run now
}
解决方案 2:创建新数据库或使用您的应用程序预加载附带的数据库。
// Titanium will create it if it doesn't exists, or return a reference to it if it exists (after first call & after app install)
var db = Ti.Database.open('your_db');
// create a new table to store properties states
db.execute('CREATE TABLE IF NOT EXISTS deletedProperties(id INTEGER PRIMARY KEY, property_name TEXT);');
// query the database to know if it contains any row with the desired property name
var result = db.execute('select * from deletedProperties where name=?', "My_Property");
if (result.rowCount == 0) { // means no property exists with such name
// first delete the desired property
Ti.App.Properties.removeProperty("My_Property");
// insert this property name in table so it can be available to let you know you have deleted the desired property
db.execute('insert into deletedProperties(name) values(?)', "My_Property");
} else {
// you have already deleted the property, 'if' block won't run now
}
// never forget to close the database after no use of it
db.close();
也可以有其他方法,但这两种方法都能满足您的需求。 Read more about Ti.Database here
我写了一个脚本,允许您删除应用程序缓存中的 属性,但是我只需要在安装应用程序时 运行 这个脚本一次。 有人有想法,谢谢
var executed = 0;
if(executed === 0){
Ti.App.Properties.removeProperty("My_Property");
executed++;
}
您可以在应用程序会话中保留一些价值的唯一方法是 Ti.App.Properties 或 sql 数据库。因此,您可以通过以下两种方式进行操作:
解决方法一:用另一个属性知道你删除了想要的属性.
// for first time installation, the default value (or 2nd parameter) will be false as you have not deleted the property yet
var isDeleted = Ti.App.Properties.getBool('My_Property_Deleted', false);
if (isDeleted) {
Ti.App.Properties.removeProperty("My_Property");
// since you have deleted it, now set it to true so this 'if' block doesn't runs on any next app session
Ti.App.Properties.setBool('My_Property_Deleted', true);
} else {
// you have already deleted the property, 'if' block won't run now
}
解决方案 2:创建新数据库或使用您的应用程序预加载附带的数据库。
// Titanium will create it if it doesn't exists, or return a reference to it if it exists (after first call & after app install)
var db = Ti.Database.open('your_db');
// create a new table to store properties states
db.execute('CREATE TABLE IF NOT EXISTS deletedProperties(id INTEGER PRIMARY KEY, property_name TEXT);');
// query the database to know if it contains any row with the desired property name
var result = db.execute('select * from deletedProperties where name=?', "My_Property");
if (result.rowCount == 0) { // means no property exists with such name
// first delete the desired property
Ti.App.Properties.removeProperty("My_Property");
// insert this property name in table so it can be available to let you know you have deleted the desired property
db.execute('insert into deletedProperties(name) values(?)', "My_Property");
} else {
// you have already deleted the property, 'if' block won't run now
}
// never forget to close the database after no use of it
db.close();
也可以有其他方法,但这两种方法都能满足您的需求。 Read more about Ti.Database here