我正在尝试从Android上的Ionic-Native的NativeStorage中检索一个密钥。我可以从iOS上的存储中检索数据,但在Android上,对NativeStorage的调用会导致异常。
我通常设置和g数据存储中的数据如下所示:
$cordovaNativeStorage.setItem('test', 'value').then(
function(){
console.log('successfully set item');
$cordovaNativeStorage.getItem('test', 'value').then(
function(result){
console.log('Set item and got it back. Value is' + result);
}, function(){
console.log('Set item but could not get it back')
});
}, function(){
console.log('could not set item at all');
});
但是,当我尝试将数据设置为存储(或将其恢复)时,我收到此错误:
TypeError: Cannot read property 'split' of undefined
at Object.get (http://xxx.xxx.xxx.xxx:8100/lib/ionic-native/ionic.native.js:15252:32)
at Object.exports.getPlugin (http://xxx.xxx.xxx.xxx:8100/lib/ionic-native/ionic.native.js:12524:19)
at callCordovaPlugin (http://xxx.xxx.xxx.xxx:8100/lib/ionic-native/ionic.native.js:12602:34)
at http://xxx.xxx.xxx.xxx:8100/lib/ionic-native/ionic.native.js:12651:24
at http://xxx.xxx.xxx.xxx:8100/lib/ionic-native/ionic.native.js:12635:17
at Q (http://xxx.xxx.xxx.xxx:8100/lib/ionic/js/ionic.bundle.js:29396:5)
at getPromise (http://xxx.xxx.xxx.xxx:8100/lib/ionic-native/ionic.native.js:12634:20)
at wrapPromise (http://xxx.xxx.xxx.xxx:8100/lib/ionic-native/ionic.native.js:12650:13)
at Object.<anonymous> (http://xxx.xxx.xxx.xxx:8100/lib/ionic-native/ionic.native.js:12817:20)
at Object.value [as getItem] (http://xxx.xxx.xxx.xxx:8100/lib/ionic-native/ionic.native.js:12868:61) {}
我查看了有问题的Ionic Native(v2.9.0)代码并找到了抛出异常的位置:第15252行,for (var i = 0, path = path.split('.'), len = path.length; i < len; i++) {
:
{"./plugin":78}],105:[function(require,module,exports){
"use strict";
function get(obj, path) {
for (var i = 0, path = path.split('.'), len = path.length; i < len; i++) {
if (!obj) {
return null;
}
obj = obj[path[i]];
}
return obj;
}
exports.get = get;
;
所以似乎path
未在此get()
函数中定义,这似乎是用于获取Cordova插件的辅助函数。我为Android和iOS安装了cordova-plugin-nativestorage
,为什么它找不到path
超出了我的范围。
有谁知道这里的问题是什么?
只是为了好玩,ionic info
的输出:
cli packages: (/usr/local/lib/node_modules)
@ionic/cli-utils : 1.19.0
ionic (Ionic CLI) : 3.19.0
global packages:
cordova (Cordova CLI) : 7.1.0
local packages:
Cordova Platforms : android 6.2.3 browser 5.0.1 ios 4.4.0 osx 4.0.1
Ionic Framework : ionic1 1.3.2
System:
ios-deploy : 1.9.2
ios-sim : 5.0.13
Node : v7.2.0
npm : 2.15.12
OS : macOS Sierra
Xcode : Xcode 9.2 Build version 9C40b
Environment Variables:
ANDROID_HOME : not set
Misc:
backend : pro