ionic项目打包好Xcode工程,模拟器运行各种沙盒缓存目录
Posted wjwdive
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ionic项目打包好Xcode工程,模拟器运行各种沙盒缓存目录相关的知识,希望对你有一定的参考价值。
用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
1 angular.module(\'starter.eamDB\', []) 2 .factory("myDB", function ($q, $cordovaSQLite, $ionicPlatform) { 3 var db; 4 var is_debug = false; 5 return { 6 openDB: function (dbname, background, func) { 7 if (window.cordova) { 8 $ionicPlatform.ready(function () { 9 var options = {name: dbname, location: \'default\'}; 10 if (typeof background != \'function\') { 11 db = $cordovaSQLite.openDB(options, background); 12 } else { 13 func = background; 14 db = $cordovaSQLite.openDB(options); 15 } 16 if ($.isFunction(func)) { 17 func(); 18 } 19 }); 20 return db; 21 } else { 22 //使用本地存储。 23 if (typeof background == \'function\') { 24 func = background; 25 } 26 // console.log(window.openDatabase(dbname, "1.0", "", 1024 * 1024 * 100, func)); 27 return db = window.openDatabase(dbname, "", "", 1024 * 1024 * 100, func); 28 } 29 }, 30 deleteDB: function (dbName) { 31 if (window.cordova && is_debug == false) { 32 return $cordovaSQLite.deleteDB(dbName); 33 } else { 34 35 } 36 }, 37 execute: function (db, query, binding) { 38 // console.log("query " + query); 39 40 if (window.cordova && is_debug == false) { 41 return $cordovaSQLite.execute(db, query, binding); 42 } else { 43 var q = $q.defer(); 44 db.transaction(function (tx) { 45 tx.executeSql(query, binding, function (tx, result) { 46 q.resolve(result); 47 }, 48 function (transaction, error) { 49 console.log(JSON.stringify(error.message)); 50 q.reject(error); 51 }); 52 }); 53 return q.promise; 54 } 55 }, 56 executeBatchSqls: function (db, batchSqls) { 57 var defer = $q.defer(); 58 var start = new Date; 59 db.transaction(function (tx) { 60 async.eachSeries(batchSqls, function (sql, callback) { 61 var inStart = new Date; 62 try { 63 tx.executeSql(sql, null, function (tx, result) { 64 console.log("执行 " + sql + " 耗时: " + (new Date - inStart) + " ms"); 65 callback(null, result); 66 }, function (transaction, error) { 67 console.error("执行 " + sql + " 出错"); 68 callback(error); 69 }); 70 } catch (exception) { 71 console.error("执行 " + sql + " 出现异常"+JSON.stringify(exception,undefined,2)); 72 callback(exception); 73 } 74 }, function (err) { 75 console.log("执行批量sqls总共耗时:" + (new Date - start) + " ms"); 76 if (err) { 77 console.error(err); 78 defer.reject(err); 79 } else { 80 defer.resolve(); 81 } 82 }); 83 }); 84 return defer.promise; 85 }, 86 insertCollection: function (db, query, bindings) { 87 if (window.cordova && is_debug == false) { 88 return $cordovaSQLite.insertCollection(db, query, bindings); 89 } else { 90 var q = $q.defer(); 91 var coll = bindings.slice(0); // clone collection 92 db.transaction(function (tx) { 93 (function insertOne() { 94 var record = coll.splice(0, 1)[0]; // get the first record of coll and reduce coll by one 95 try { 96 tx.executeSql(query, record, function (tx, result) { 97 if (coll.length === 0) { 98 q.resolve(result); 99 } else { 100 insertOne(); 101 } 102 }, function (transaction, error) { 103 q.reject(error); 104 return; 105 }); 106 } catch (exception) { 107 q.reject(exception); 108 } 109 })(); 110 }); 111 return q.promise; 112 } 113 }, 114 nestedExecute: function (db, query1, query2, binding1, binding2) { 115 if (window.cordova && is_debug == false) { 116 return $cordovaSQLite.nestedExecute(db, query1, query2, binding1, binding2); 117 } else { 118 var q = $q.defer(); 119 db.transaction(function (tx) { 120 tx.executeSql(query1, binding1, function (tx, result) { 121 q.resolve(result); 122 tx.executeSql(query2, binding2, function (tx, res) { 123 q.resolve(res); 124 }); 125 }); 126 }, 127 function (transaction, error) { 128 q.reject(error); 129 }); 130 131 return q.promise; 132 } 133 } 134 } 135 });
使用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/
以上是关于ionic项目打包好Xcode工程,模拟器运行各种沙盒缓存目录的主要内容,如果未能解决你的问题,请参考以下文章
Xcode 设备列表在 ionic/cordova 项目中为空
Xcode怎么设置启动的iOS模拟器的系统版本? 比如我现在调试项目模拟器默认运行的是iOS9.0
将 Capacitor 集成到 Ionic 项目后无法在 Xcode 中运行
关于 从别人电脑上 高版本的 Xcode上拷贝过来的项目的 不能运行模拟器的 解决方法
Ionic 3/Cordova:应用程序通过 Ionic CLI 而不是通过 Xcode 运行(在 Xcode 中构建成功)