2016-06-28 21 views
2

Hallo Ich verwende Phonegap, um iOS-Anwendung zu erstellen. Ich verwende die Filetransfer-API, um die Bilddatei herunterzuladen. Ich verwende folgende Code-DateiFehler beim Herunterladen der Datei in Phonegap iOS

 window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, createFolder, null); 

    function createFolder(fileSystem) { 
     console.log('gotFS'); 
     fileSystem.root.getDirectory("MyDirectory", { 
          create: true, 
          exclusive: false 
          }, MyDirectorySuccess, MyDirectoryfail); 
    } 

    function MyDirectorySuccess(entry) { 
     console.log('gotDirectorySuccess'); 
     downloadFile(entry); 
    } 
    function downloadFile(entry) 
    { 
     console.log('downloadFile'); 

     var filePath = entry.fullPath+'test.jpg'; 
     var fileTransfer = new FileTransfer(); 
     var url = 'https://www.facebookbrand.com/img/fb-art.jpg'; 

     fileTransfer.download(
         url, filePath, function(entry) { 
         console.log("success"); 
         }, function(error) { 
         console.log("error"); 
         }, true, {}); 
    } 

zum Download Wenn ich es auf dem iOS-Gerät laufe i Störung erhalten:

FileTransferError { 
    body = "Could not create path to save downloaded file: You don\U2019t have permission to save the file \U201cMyRecipeDirectory\U201d in the folder \U201cMonarch13A452.J72OS\U201d."; 
    code = 1; 
    "http_status" = 200; 
    source = "https://www.facebookbrand.com/img/fb-art.jpg"; 
    target = "cdvfile://localhost/root/MyDirectory/test.jpg"; 
} 

Wie kann ich dieses Problem lösen?

Antwort

1

Dies ist ein komplexer Fehler zwischen cordova-plugin-file-transfer und cordova-plugin-file plugins.
FileTransfer Plugin verwendet Typ "root" zu Datei-Plugin. Es ist Standard und kann keine Typen ändern.
Der Pfad von "root" ist "/", das ist die Ursache des Problems.
Zum Beispiel ist der Pfad von "persistent" "/ user/{Ihr Name}/Library/..." auf dem iPhone-Simulator.
Sie können nicht auf "/" zugreifen.

Ich habe versucht, @ "root" Pfad in getAvailableFileSystems() -Methode, CDVFile.m von CordovaLib.xcodeproj zu ändern.
Die App stürzte jedoch ab, nachdem sie eingestellt wurde.
Es gibt keinen schlauen Weg, ich entschied mich dafür, die Art zu ändern, die Schnur unnatürlich zu ändern.

Download() -Methode in CDVFileTransfer.m Linie 440

target = [target stringByReplacingOccurrencesOfString:@"//" withString:@"/"]; 
targetURL = [[self.commandDelegate getCommandInstance:@"File"] fileSystemURLforLocalPath:target].url; 

add Code unter dieser.

NSString *absoluteURL = [targetURL absoluteString]; 
if ([absoluteURL hasPrefix:@"cdvfile://localhost/root/"]) { 
     absoluteURL = [absoluteURL stringByReplacingOccurrencesOfString:@"cdvfile://localhost/root/" withString:@"cdvfile://localhost/persistent/"]; 
     targetURL = [NSURL URLWithString:absoluteURL]; 
}