FranGhe commented on issue #1299:
URL: https://github.com/apache/cordova-ios/issues/1299#issuecomment-1477121329

   This is the solution... no one setting server side...
   
   Install 
[cordova-plugin-wkwebview-file-xhr](https://github.com/oracle/cordova-plugin-wkwebview-file-xhr)
 and 
[cordova-plugin-wkwebviewxhrfix](https://github.com/TheMattRay/cordova-plugin-wkwebviewxhrfix)
 plugins
   
   On config.xml set:
   ```
   <platform name="ios">    
     <preference name="scheme" value="app" />
     <preference name="hostname" value="localhost" />
     ...
   </platform>
   ```
   Than, to download the files:
   ```
   function downloadTemporaryFile(pathOrig, key, pathDest) {
     var req = new XMLHttpRequest();
     req.open("GET", pathOrig, true);
     req.responseType = "blob";
     req.onload = function (event) {
         var blob = req.response;
         var storageLocation = cordova.file.dataDirectory;
   
         if(storageLocation){
             window.resolveLocalFileSystemURL(
                 storageLocation, 
                 function (directoryEntry) {
                     directoryEntry.getFile(
                         pathDest,
                         { create: true }, 
                         function (fileEntry) {
                             fileEntry.createWriter(
                                 function (fileWriter) {
                                     fileWriter.write(blob);
                                     fileWriter.onwriteend = function (e) { 
                                         //console.log('Write of file 
completed.'); 
                                         var split=pathDest.split("-");
                                         var cont=split[0];
                                         var thisContent=allAppData[cont];
                                         var localFile = 
storageLocation+pathDest;
                                         if(!thisContent["temporaryImages"]){
                                             thisContent.temporaryImages={};
                                         }
                                         if(device.platform === "Android"){
                                             
thisContent.temporaryImages[key]=localFile;
                                         }
                                         else if(device.platform === "iOS"){
                                             
thisContent.temporaryImages[key]=window.WkWebView.convertFilePath(localFile);
                                         }
                                     };
                                     fileWriter.onerror = function (e) { 
console.log("downloadTemporaryFile -> Err01"); };
                                 },
                                 function (err) {
                                     console.log("downloadTemporaryFile -> 
Err02");
                                     console.error(err);
                                 }
                             );
                         },
                         function (err) {
                             console.log("downloadTemporaryFile -> Err03");
                             console.error(err);
                         }
                     );
                 },
                 function (err) {
                     console.log("downloadTemporaryFile -> Err04");
                     console.error(err);
                 }
             );
         }
     };
   req.send();
   }
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to