Javascript 如何使用phonegap2.0在iphone上创建文件

Javascript 如何使用phonegap2.0在iphone上创建文件,javascript,ios,html,Javascript,Ios,Html,我也不熟悉iphone和phonegap。现在我想使用phonegap在iphone中创建文件。我点击了以下链接: "http://docs.phonegap.com/en/2.0.0/cordova_file_file.md.html#File" 在这个链接中有一个带有javascript的html文件。所以我遵循了编码。当我运行代码时,我只得到html标记内容的输出 I have attach that coding with my output. <!DOCTYPE ht

我也不熟悉iphone和phonegap。现在我想使用phonegap在iphone中创建
文件
。我点击了以下链接:

 "http://docs.phonegap.com/en/2.0.0/cordova_file_file.md.html#File"
在这个链接中有一个带有javascript的html文件。所以我遵循了编码。当我运行代码时,我只得到html标记内容的输出

I have attach that coding with my output.
    <!DOCTYPE html>
<html>
  <head>
    <title>FileReader Example</title>![enter image description here][1]

    <script type="text/javascript" charset="utf-8" src="cordova-2.0.0.js"></script>
    <script type="text/javascript" charset="utf-8">

    // Wait for Cordova to load
    //
    function onLoad() {
        document.addEventListener("deviceready", onDeviceReady, false);
    }

    // Cordova is ready
    //
    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(error) {
        console.log(error.code);
    }

    </script>
  </head>
  <body>
    <h1>Example</h1>
    <p>Read File</p>
  </body>
</html>



"TestPhonegapApp[9589:707] CDVPlugin class CDVDevice (pluginName: Device) does not exist.
2012-09-11 12:02:13.719 TestPhonegapApp[9589:707] ERROR: Plugin 'Device' not found, or is not a CDVPlugin. Check your plugin mapping in Cordova.plist.
2012-09-11 12:02:13.722 TestPhonegapApp[9589:707] FAILED pluginJSON = {"className":"Device","methodName":"getDeviceInfo","arguments":["Device1"]}"
我已将该编码附加到我的输出中。
文件阅读器示例![在此处输入图像描述][1]
//等待Cordova加载
//
函数onLoad(){
文件。添加的监听器(“deviceready”,OnDeviceraddy,false);
}
//科尔多瓦准备好了
//
函数ondevicerady(){
requestFileSystem(LocalFileSystem.PERSISTENT,0,gotFS,fail);
}
函数gotFS(文件系统){
getFile(“readme.txt”,null,gotFileEntry,fail);
}
函数gotFileEntry(fileEntry){
fileEntry.file(gotFile,fail);
}
函数gotFile(文件){
readDataUrl(文件);
readAsText(文件);
}
函数readDataUrl(文件){
var reader=new FileReader();
reader.onloadend=函数(evt){
log(“读取为数据URL”);
日志(evt.target.result);
};
reader.readAsDataURL(文件);
}
函数readAsText(文件){
var reader=new FileReader();
reader.onloadend=函数(evt){
console.log(“读取为文本”);
日志(evt.target.result);
};
reader.readAsText(文件);
}
功能失败(错误){
console.log(错误代码);
}
例子
读取文件

“TestPhonegapApp[9589:707]CDVPlugin类CDVDevice(pluginName:Device)不存在。 2012-09-11 12:02:13.719 TestPhonegapApp[9589:707]错误:找不到插件“设备”,或者插件不是CDVPlugin。请在Cordova.plist中检查插件映射。 2012-09-11 12:02:13.722 TestPhonegapApp[9589:707]失败的pluginJSON={“className”:“Device”,“methodName”:“getDeviceInfo”,“arguments”:[“Device1”]}


嗨!我认为您使用的示例是读取文件。您可能需要检查如何写入文件:。希望这个链接有帮助。谢谢回复。我在你的指导下试过编码。但很抱歉,我得到了相同的输出。请给我更多的想法来澄清这个问题。我正在使用phonegap2.0版本。。。。抱歉耽搁了。。。疯狂的撞车。。不管怎样,您是否修改了您的文件
Cordova.plist
?你的控制台显示了什么吗?谢谢你的回复。我在我的问题中编辑了cordova.plist供你参考。而且我在xcode4.3调试器控制台中收到了一些错误消息。当我在设备中运行代码时,我收到了这些消息。我已经在我的问题中编辑了错误消息,供您参考。让我们