ios - Javascript and Cordova/Phonegap FileWriter gives Invalid_Modification_Error on a simple text file write -
i using cordova file , filetransfer plugins. have following permissions set in config.xml
<feature name="file"> <param name="ios-package" value="cdvfile" /> </feature> <feature name="filetransfer"> <param name="ios-package" value="cdvfiletransfer" /> </feature> i trying write plain text file using following piece of code:
this.writefile = function (filename, content, type, callback) { window.resolvelocalfilesystemurl(cordova.file.applicationdirectory, function(dir) { dir.getfile(filename, { create: true }, function(fileentry) { fileentry.createwriter(function(filewriter) { filewriter.onwriteend = function(e) { console.log('write success'); callback(null, e); }; filewriter.onerror = function(e) { console.log('write error is'); console.log(e); callback(e); }; var blob = new blob([content], {type: type}); filewriter.write(blob); }, callback); }, callback); }, callback); }; when execute line below:
this.writefile('stuff.txt', 'eggs , burgers', 'text/plain', callback); i error while writing file code 9, translates invalid_modification_error. mean? permissions? how can give filesystem permissions app in xcode or cordova?
another issue callback function gets called twice! once success , once error. understand writeend not mean successful operation, how handle situations this?
note issue happens on actual ios device. in ios simulator, runs , writes fine on filesystem. after resolving how write text file, go on , write png/mp3/wav files well.
i appreciate help. thanks.
turns out there nothing wrong code above, except apple forbids writing app bundle after bundle installed. bundle signed , no modifications allowed after that.
to able write data, change
cordova.file.applicationdirectory to
cordova.file.datadirectory and add following config.xml according needs:
<preference name="iospersistentfilelocation" value="library" /> your data stored in library/nocloud directory in ios.
further reading on ios filesystem: https://developer.apple.com/library/ios/documentation/filemanagement/conceptual/filesystemprogrammingguide/filesystemoverview/filesystemoverview.html
Comments
Post a Comment