用ionic开发好的app,build好iOS端可用的Xcode工程,然后用模拟器跑起来。研究一下js写的代码做本地持久化时,不同类型的文件都放在那里了。
cordova-plugin-sqliteStorage插件创建的数据库的在沙盒中文件位置,默认使用参数default。
/Users/userName/Library/Developer/CoreSimulator/Devices/udid/data/Containers/Data/Application/9609D07D-0618-4ADB-8A07-CC46D898EC09/Library/dabaseName.db
angular.module('starter.eamDB', [])
.factory("myDB", function ($q, $cordovaSQLite, $ionicPlatform) {
var db;
var is_debug = false;
return {
openDB: function (dbname, background, func) {
if (window.cordova) {
$ionicPlatform.ready(function () {
var options = {name: dbname, location: 'default'};
if (typeof background != 'function') {
db = $cordovaSQLite.openDB(options, background);
} else {
func = background;
db = $cordovaSQLite.openDB(options);
}
if ($.isFunction(func)) {
func();
}
});
return db;
} else {
//使用本地存储。
if (typeof background == 'function') {
func = background;
}
// console.log(window.openDatabase(dbname, "1.0", "", 1024 * 1024 * 100, func));
return db = window.openDatabase(dbname, "", "", 1024 * 1024 * 100, func);
}
},
deleteDB: function (dbName) {
if (window.cordova && is_debug == false) {
return $cordovaSQLite.deleteDB(dbName);
} else { }
},
execute: function (db, query, binding) {
// console.log("query " + query); if (window.cordova && is_debug == false) {
return $cordovaSQLite.execute(db, query, binding);
} else {
var q = $q.defer();
db.transaction(function (tx) {
tx.executeSql(query, binding, function (tx, result) {
q.resolve(result);
},
function (transaction, error) {
console.log(JSON.stringify(error.message));
q.reject(error);
});
});
return q.promise;
}
},
executeBatchSqls: function (db, batchSqls) {
var defer = $q.defer();
var start = new Date;
db.transaction(function (tx) {
async.eachSeries(batchSqls, function (sql, callback) {
var inStart = new Date;
try {
tx.executeSql(sql, null, function (tx, result) {
console.log("执行 " + sql + " 耗时: " + (new Date - inStart) + " ms");
callback(null, result);
}, function (transaction, error) {
console.error("执行 " + sql + " 出错");
callback(error);
});
} catch (exception) {
console.error("执行 " + sql + " 出现异常"+JSON.stringify(exception,undefined,2));
callback(exception);
}
}, function (err) {
console.log("执行批量sqls总共耗时:" + (new Date - start) + " ms");
if (err) {
console.error(err);
defer.reject(err);
} else {
defer.resolve();
}
});
});
return defer.promise;
},
insertCollection: function (db, query, bindings) {
if (window.cordova && is_debug == false) {
return $cordovaSQLite.insertCollection(db, query, bindings);
} else {
var q = $q.defer();
var coll = bindings.slice(0); // clone collection
db.transaction(function (tx) {
(function insertOne() {
var record = coll.splice(0, 1)[0]; // get the first record of coll and reduce coll by one
try {
tx.executeSql(query, record, function (tx, result) {
if (coll.length === 0) {
q.resolve(result);
} else {
insertOne();
}
}, function (transaction, error) {
q.reject(error);
return;
});
} catch (exception) {
q.reject(exception);
}
})();
});
return q.promise;
}
},
nestedExecute: function (db, query1, query2, binding1, binding2) {
if (window.cordova && is_debug == false) {
return $cordovaSQLite.nestedExecute(db, query1, query2, binding1, binding2);
} else {
var q = $q.defer();
db.transaction(function (tx) {
tx.executeSql(query1, binding1, function (tx, result) {
q.resolve(result);
tx.executeSql(query2, binding2, function (tx, res) {
q.resolve(res);
});
});
},
function (transaction, error) {
q.reject(error);
}); return q.promise;
}
}
}
});
使用localstorage创建的一些本地缓存存储的记录的路径
/Users/userName/Library/Developer/CoreSimulator/Devices/udid/data/Containers/Data/Application/9609D07D-0618-4ADB-8A07-CC46D898EC09/Library/Caches/appIdentifier/nsurlcache/...
或
/Users/userName/Library/Developer/CoreSimulator/Devices/udid/data/Containers/Data/Application/9609D07D-0618-4ADB-8A07-CC46D898EC09/Library/Caches/...localstroage
诸如此类文件:
file__0.localstorage
file__0.localstorage-shm
file__0.localstorage-wal
从图库中选择的图片的路径
/Users/userName/Library/Developer/CoreSimulator/Devices/udid/data/Containers/Data/Application/9609D07D-0618-4ADB-8A07-CC46D898EC09/tem/