cordova-plugin-file in Chrome: cordova is not defined

后端 未结 2 636
情书的邮戳
情书的邮戳 2021-02-20 03:31

I use cordova-plugin-file in my ionic app to download images and save to local.

When I run it in emulator or iphone, there is no error, but when I test it in Chrome, it

2条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-20 04:09

    What you easily could do is copy cordova.js yourself to your root directory for testing.The file resides e.g in the directory

    cordova-project/platforms/ios/platform_www

    You could easily just copy it over. If you do it the cordova object is available and can be accessed in your code e.g.

    cordova.file.dataDirectory
    

    A good approach for debugging and testing Cordova applications is the Cordova browser plugin in conjunction with Phonegap installed to get access to the

    phonegap serve browser 
    

    command. That way you can conveniently test your application right on your computer and don't have to send it to your device. It needs to be said that above mentioned cordova.file.dataDirectory is not available on your computer. Some plugins provide proxies for the browser platform that you could test them in your browser, too. For me the good thing with phonegap serve browser is when you edit your code and save it and then reload your browser the change get reflected.

    I have to mention one more point to get the code changes reflection working.You have to create a

    .cordova

    directory inside your Cordova project root folder. Then you have to add a config.json file inside with following content:

    {
    "lib": {
        "www": {
            "id": "com.phonegap.helloworld",
            "version": "3.5.0",
            "uri": "https://github.com/phonegap/phonegap-app-hello-world/archive/3.5.0.tar.gz"
        }
    }
    }
    

    As stated in following post from SO: Get phone gap serve working in Cordova project

提交回复
热议问题