简体   繁体   中英

Download image from url in ios phonegap

I am trying to download an image from a url and was not successful in ios but in android it was succesfully done.

var url = "http://www.intelligrape.com/images/logo.png"; // image url
try{
    window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function (fs) {
        var imagePath = fs.root.fullPath + "/logo.png"; // full file path
        var fileTransfer = new FileTransfer();
        fileTransfer.download(url, imagePath, function (entry) {
            alert(entry.fullPath); // entry is fileEntry object
        }, function (error) {
            alert("Some error");
        });
    })
 }catch(e){
    alert(e);
 }

I am getting error of LocalFileSystem is not defined. i am including cordova2.5.0.js with this.

My Config.xml is below.

<?xml version="1.0" encoding="UTF-8"?>
<cordova>
<preference name="KeyboardDisplayRequiresUserAction" value="true" />
<preference name="SuppressesIncrementalRendering" value="false" />
<preference name="UIWebViewBounce" value="true" />
<preference name="TopActivityIndicator" value="gray" />
<preference name="EnableLocation" value="false" />
<preference name="EnableViewportScale" value="false" />
<preference name="AutoHideSplashScreen" value="true" />
<preference name="ShowSplashScreenSpinner" value="true" />
<preference name="MediaPlaybackRequiresUserAction" value="false" />
<preference name="AllowInlineMediaPlayback" value="false" />
<preference name="OpenAllWhitelistURLsInWebView" value="false" />
<preference name="BackupWebStorage" value="cloud" />

<plugins>
    <plugin name="Device" value="CDVDevice" />
    <plugin name="Logger" value="CDVLogger" />
    <plugin name="Compass" value="CDVLocation" />
    <plugin name="Accelerometer" value="CDVAccelerometer" />
    <plugin name="Camera" value="CDVCamera" />
    <plugin name="NetworkStatus" value="CDVConnection" />
    <plugin name="Contacts" value="CDVContacts" />
    <plugin name="Debug Console" value="CDVDebugConsole" />
    <plugin name="Echo" value="CDVEcho" />
    <plugin name="File" value="CDVFile" />
    <plugin name="FileTransfer" value="CDVFileTransfer" />
    <plugin name="Geolocation" value="CDVLocation" />
    <plugin name="Notification" value="CDVNotification" />
    <plugin name="Media" value="CDVSound" />
    <plugin name="Capture" value="CDVCapture" />
    <plugin name="SplashScreen" value="CDVSplashScreen" />
    <plugin name="Battery" value="CDVBattery" />
    <plugin name="Globalization" value="CDVGlobalization" />
     <plugin name="InAppBrowser" value="CDVInAppBrowser" />
   </plugins>

   <access origin="*" />
</cordova>

include cordova2.5.0.js file prior than all custom js files . you might be including it after your code

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM