Uzyskaj dostęp do plików za pomocą funkcji Phonegap
Próbuję pracować z plikami na IOS, używając Phonegap [cordova 1.7.0]. Czytałem, jak uzyskać dostęp do plików i przeczytać je na stronieDokumentacja API luki telefonicznej. Ale nie wiem, kiedy plik zostanie przeczytany, gdzie będzie napisany? & Jak mogę wydrukować tekst, obraz lub cokolwiek zawierającego tekst na ekranie iPhone'a?
Oto kod, którego używam:
<code> function onDeviceReady() { window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail); } function gotFS(fileSystem) { fileSystem.root.getFile("readme.txt", null, gotFileEntry, fail); } function gotFileEntry(fileEntry) { fileEntry.file(gotFile, fail); } function gotFile(file){ readDataUrl(file); readAsText(file); } function readDataUrl(file) { var reader = new FileReader(); reader.onloadend = function(evt) { console.log("Read as data URL"); console.log(evt.target.result); }; reader.readAsDataURL(file); } function readAsText(file) { var reader = new FileReader(); reader.onloadend = function(evt) { console.log("Read as text"); console.log(evt.target.result); }; reader.readAsText(file); } function fail(evt) { console.log(evt.target.error.code); } </code>