2013-02-19 45 views
0

我目前正在研究PhoneGap在iPhone應用程序開發中可以做什麼/不能做什麼。到目前爲止,我已經設法使用FileWriter將文件寫入LocalFileSystem,並單擊按鈕將文件讀回給用戶。我被要求找到一種方法來設置應用程序,以便在應用程序寫入文件時將文件保存到用戶指定的文件夾/位置。我一直在尋找,但我找不到任何有關這方面的信息。它甚至有可能這樣做嗎?如果是這樣,你能幫我嗎?是否可以在手機間隙中設置特定的文件路徑?

我使用JavaScript,HTML和的PhoneGap在Xcode這個應用

這裏是我以前寫/使用LocalFileSystem讀取文件的代碼;

var reader; 
    var text; 
    var myFileSystem; 

    document.addEventListener("deviceready", onDeviceReady, false); 

    function onDeviceReady() { 
     window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail); 
    } 

    function myfile() { 
     window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotmyFS, fail); 
    } 

    function gotFS(fileSystem) { 
     fileSystem.root.getFile("readme.txt", {create: true, exclusive: false}, gotFileEntry, fail); 
     myFileSystem = fileSystem; 
     console.log(fileSystem.name); 
    } 

    function gotmyFS(fileSystem) { 
     fileSystem.root.getFile("readme2.txt", {create: true, exclusive: false}, gotFileEntry, fail); 
    } 

    function gotFileEntry(fileEntry) { 
     fileEntry.createWriter(gotFileWriter, fail); 
     fileEntry.file(gotFile, fail); 
    } 

    function gotFileWriter(writer) { 
     writer.write("some sample text"); 
    } 

    function gotFile(file){ 
     readAsText(file); 
    } 

    function readDataUrl(file) { 
     reader = new FileReader(); 
     reader.onloadend = function(evt) { 
      console.log("Read as data URL"); 
      console.log(evt.target.result); 
     }; 
     reader.readAsDataURL(file); 
    } 

    function readAsText(file) { 
     reader = new FileReader(); 
     reader.onloadend = function(evt) { 
      console.log("Read as text"); 
      console.log(evt.target.result); 
      console.log(file); 
      text = evt.target.result; 
     }; 
     reader.readAsText(file); 
    } 

    function readmyfile() { 
     var myPara = document.getElementById("mytext"); 
     myPara.innerText = text; 
    } 
    function fail(error) { 
     console.log(error.code); 
    } 

這一切都有效,但有什麼我應該添加/刪除,使其工作?

感謝很多提前XX

回答

0

iOS應用沙盒是,你可以寫只對特定目錄。更多詳情here

+0

非常感謝:) xx – 2013-02-19 15:05:48

相關問題