質問編集履歴
2
内容、プログラムの追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -2,20 +2,64 @@
|
|
2
2
|
Monacaを用いたアプリ作成で、iphone,ipad上でcsvを作成してdocuments等を利用してPCにファイルを落としたい。
|
3
3
|
iphone,ipad上で作成したファイルを開く予定はありません。
|
4
4
|
###発生している問題
|
5
|
-
Monaca docsの「ファイル操作プラグイン」に載っていた例から作ってみたのですが、デバッガーで
|
5
|
+
Monaca docsの「ファイル操作プラグイン」に載っていた例から作ってみたのですが、デバッガーで作成したところ、作成はされているようなのですが、それを他のアプリ、もしくはMonaca内で確認する方法がわかりません。
|
6
6
|
以下がそのページになります。
|
7
7
|
[https://docs.monaca.io/ja/reference/cordova_3.5/file/](http://docs.monaca.io/ja/reference/cordova_3.5/file/)
|
8
8
|
###ソースコード
|
9
9
|
```JavaScript
|
10
|
+
function wrt(content){
|
10
|
-
var blob = new Blob([ bom, content ], { "type" : "sample/csv" });
|
11
|
+
var blob = new Blob([ bom, content ], { "type" : "sample/csv" });
|
11
|
-
if(monaca.isIOS){
|
12
|
+
if(monaca.isIOS){
|
12
|
-
|
13
|
+
window.resolveLocalFileSystemURL(cordova.file.syncedDataDirectory, function
|
14
|
+
(dirEntry) {
|
13
|
-
|
15
|
+
var isAppend = true;
|
14
|
-
|
16
|
+
createFile(dirEntry,"sample.csv", isAppend,blob);
|
17
|
+
}, Error);
|
18
|
+
}
|
19
|
+
}
|
20
|
+
function createFile(dirEntry, fileName, isAppend,dataObj) {
|
21
|
+
// Creates a new file or returns the file if it already exists.
|
22
|
+
dirEntry.getFile(fileName, {create: true, exclusive: false}, function(fileEntry) {
|
23
|
+
writeFile(fileEntry, dataObj, isAppend);
|
15
24
|
}, Error);
|
25
|
+
|
16
26
|
}
|
27
|
+
function writeFile(fileEntry, dataObj, isAppend) {
|
28
|
+
// Create a FileWriter object for our FileEntry (log.txt).
|
29
|
+
fileEntry.createWriter(function (fileWriter) {
|
30
|
+
fileWriter.onwriteend = function() {
|
31
|
+
console.log("Successful file write...");
|
32
|
+
readFile(fileEntry);
|
33
|
+
};
|
34
|
+
fileWriter.onerror = function (e) {
|
35
|
+
console.log("Failed file read: " + e.toString());
|
36
|
+
};
|
37
|
+
// If we are appending data to file, go to the end of the file.
|
38
|
+
if (isAppend) {
|
39
|
+
try {
|
40
|
+
fileWriter.seek(fileWriter.length);
|
41
|
+
}
|
42
|
+
catch (e) {
|
43
|
+
console.log("file doesn't exist!");
|
44
|
+
}
|
45
|
+
}
|
46
|
+
fileWriter.write(dataObj);
|
47
|
+
});
|
48
|
+
}
|
49
|
+
function readFile(fileEntry) {
|
50
|
+
fileEntry.file(function (file) {
|
51
|
+
var reader = new FileReader();
|
52
|
+
reader.onloadend = function() {
|
53
|
+
console.log("Successful file read: ");
|
54
|
+
log(this.result);
|
55
|
+
alert(fileEntry.fullPath + ": " + this.result);
|
56
|
+
};
|
57
|
+
reader.readAsText(file);
|
58
|
+
}, Error);
|
59
|
+
}
|
17
60
|
```
|
18
61
|
###質問
|
19
62
|
現状としてプログラムに問題があるのか、何かipadの設定などプログラム以外に要因があるのか、アプリ作成自体初めてのことなので細かい部分がよくわかっていません。
|
63
|
+
プログラムの修正箇所・もしくは確認方法について、どちらか片方でもいいので、教えて頂けないでしょうか?
|
20
64
|
|
21
65
|
よろしくお願いします。
|
1
参考にしたページのURL追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -2,7 +2,9 @@
|
|
2
2
|
Monacaを用いたアプリ作成で、iphone,ipad上でcsvを作成してdocuments等を利用してPCにファイルを落としたい。
|
3
3
|
iphone,ipad上で作成したファイルを開く予定はありません。
|
4
4
|
###発生している問題
|
5
|
-
Monaca docsの「ファイル操作
|
5
|
+
Monaca docsの「ファイル操作プラグイン」に載っていた例から作ってみたのですが、デバッガーで確認すると、作成後にアラートのような形で出力したデータが表示されるだけで、documents等を開いてもありません。
|
6
|
+
以下がそのページになります。
|
7
|
+
[https://docs.monaca.io/ja/reference/cordova_3.5/file/](http://docs.monaca.io/ja/reference/cordova_3.5/file/)
|
6
8
|
###ソースコード
|
7
9
|
```JavaScript
|
8
10
|
var blob = new Blob([ bom, content ], { "type" : "sample/csv" });
|