2017-06-26 50 views
1

的特性“filesystemName”我有在下面的逻辑没有忘记第二时间我上运行的Android应用程序的应用程序:科尔多瓦错误:无法读取空

window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, 
        function(fs) { 
         console.log('Success!', fs); 
        }, 
        function(e) { 
         console.error('Fail!', e); 
        } 
       ); 

错误我得到的是:

cordova.js:312 Error in Success callbackId: File1306990920 : TypeError: Cannot read property 'filesystemName' of null

Cordova.js线312是在callbackFromNative功能的通用陷阱。

有没有人遇到过这个?

补救措施是什么?

回答

0

UPDATE

单从config.xml中删除<preference name="AndroidPersistentFileLocation" value="Compatibility" />,或更改"Compatibility""Internal",似乎是负责添加的空值的阵列响应,提及以下


我使用带有Ionic2的cordova文件插件,如果不是你的情况,也许这可以给你一些亮点。

我的这个错误的跟踪带我到.../plugins/cordova-plugin-file/www/fileSystems-roots.js,即fsName的地图 - > FileSystem。

这使我认为这是一个错误,但我不确定如何报告它。

不管怎么说,问题是到地图响应包含一个空的对象,因为你可以在下面的响应的抄见:

[ 
    null 
    , {"fullPath":"/","filesystemName":"persistent","isDirectory":true,"nativeURL":"file:...","filesystem":1,"isFile":false,"name":""} 
    , {"fullPath":"/","filesystemName":"content","isDirectory":true,"nativeURL":"content:...","filesystem":1,"isFile":false,"name":""} 
    , {"fullPath":"/","filesystemName":"assets","isDirectory":true,"nativeURL":"file:...","filesystem":1,"isFile":false,"name":""} 
    , {"fullPath":"/","filesystemName":"cache","isDirectory":true,"nativeURL":"file:...","filesystem":1,"isFile":false,"name":""} 
] 

同样,我使用ionic2,如果是你的情况同样,你可以使用文件直接插件,之后的下一个步骤:

0-安装插件(如果您收到此错误,我想你已经做了这一步)

1导入插件作为提供者在你模块中,就像

import { File } from '@ionic-native/file'; 

@NgModule({ 
    ... 
    , providers: [ 
     ... 
     , File 
     ... 
    ] 
    ... 
}) 

2-添加插件作为供应商在你的组件

import { File } from '@ionic-native/file'; 

export class FileCreatorComponent { 
    constructor(..., private file: File, ...) { } 

3-根据Ionic2 Native file plugin此页面使用它,例如创建(并覆盖是否存在),你可以这样做:

createFile() { 
    var filePath= this.file.externalRootDirectory + 'Download/'; 
    //var filePath= 'file:///storage/emulated/0/Download/'; If the first doesn't work you can put this path, NOT RECOMMENDED, because the first should work 
    var fileName= 'newOne.txt'; 

    this.file.writeFile(filePath, fileName, 'Lorem ipsum', { replace: true }) 
       .then(() => { 
        console.log('File created'); 
       }); 
}