Creating folders (fileSystem.root.getDirectory)

1,537 views
Skip to first unread message

Guillaume Bartolini

unread,
May 17, 2013, 12:30:55 AM5/17/13
to phon...@googlegroups.com
Is there restriction on creating folders and files offline in a IOS app ??

The app works fine when device is connected but running fileSystem.root.getDirectory( app.datasDir, {create: true}, success, fail); offline fails .

Any idea ??

xcode error = error creating directory: The operation couldn’t be completed. (Cocoa error 4.)

Kerri Shotts

unread,
May 17, 2013, 11:42:25 AM5/17/13
to phon...@googlegroups.com
When offline, are you in airplane mode or are you using the network link conditioner?

Not that I can see why or how it should make a difference. What version PG & iOS?

Sent from my phone. 

___________________________________
Kerri Shotts
photoKandy Studios, LLC


Social Media:
          Twitter: @photokandy, http://twitter.com/photokandy
          Tumblr: http://photokandy.tumblr.com/
          Github: https://github.com/kerrishotts
                        https://github.com/organizations/photokandyStudios
          CoderWall: https://coderwall.com/kerrishotts

Apps on the Apple Store:

Books:
--
-- You received this message because you are subscribed to the Google
Groups "phonegap" group.
To post to this group, send email to phon...@googlegroups.com
To unsubscribe from this group, send email to
phonegap+u...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/phonegap?hl=en?hl=en
 
For more info on PhoneGap or to download the code go to www.phonegap.com
 
To compile in the cloud, check out build.phonegap.com
---
You received this message because you are subscribed to the Google Groups "phonegap" group.
To unsubscribe from this group and stop receiving emails from it, send an email to phonegap+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Guillaume Bartolini

unread,
May 17, 2013, 5:19:43 PM5/17/13
to phon...@googlegroups.com
Hi Kery

Im not on airplane mode nor using the network conditioner.
IOS and PG are the latest (6.1 and 2.7)

also the folder structure i am creating is 'name/version/data' , is creating a folder structure instead of just 1 folder a problem ?
The other thing i noticed when ONLINE (this time) is that if i didn't had files after the folder creation,  the folders where not created.

Kerri Shotts

unread,
May 17, 2013, 5:39:58 PM5/17/13
to phon...@googlegroups.com
No, don't think it should be a problem, though is there any particular reason you need things specific to the version (and not sure what name is: is the name of the user? the app? etc?)… but still I wouldn't think that should matter.

What's your code?

Also, are you running on the simulator or on a real device?

___________________________________
Kerri Shotts
photoKandy Studios, LLC



Social Media:
          Twitter: @photokandy, http://twitter.com/photokandy
          Tumblr: http://photokandy.tumblr.com/
          Github: https://github.com/kerrishotts
                        https://github.com/organizations/photokandyStudios
          CoderWall: https://coderwall.com/kerrishotts

Apps on the Apple Store:

Books:

--

Guillaume Bartolini

unread,
May 17, 2013, 8:33:14 PM5/17/13
to phon...@googlegroups.com
Thanks for your help Kerri ( right spelling this time :-) )

here is the code i am using with some comments for you (simplified version)

var app = {
fs: null,
datasDir = '/appname/another_folder_as_dictated_by_my_boss/datas/',
entities : ['one', 'two', 'three', 'bar', 'foo'],
onDeviceReady: function() {
app.handleDatas();
        
        _.delay(function() {//underscore setimout
   navigator.splashscreen.hide();
}, 1000);

startApp();// loads html tpl, backbone router start etc...
},
    handleDatas: function(){
   window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, app.onFileSuccess, app.onFileFail);
    },

    onFileSuccess: function(fileSystem) {
    app.fs = fileSystem;

var filePath = app.fs.root.fullPath + app.datasDir,
fileTransfer = new FileTransfer();

fileSystem.root.getDirectory( app.datasDir, {create: true, exclusive: false}); // Get the data directory, creating it if it doesn't exist.
// i'm not using the success and fail callback so maybe the issue is there but if using it, it always fails on first app build and maybe it is normal behaviour...
       fileSystem.root.getFile( app.datasDir + "profile.json", {create:false, exclusive: false}, app.profileExist, app.firstLaunch);

_.each(app.entities, function(entity, index) {
fileTransfer.download(
   encodeURI(app.uri + entity),
   filePath + entity + ".json",
   function(entry) {

//fetch my collections from the new json fils in app.datasDir
   },
   function(error) {
if(index == 0){
app.onFileFail();
return;
}
   },
   true
);// end fileTransfer function
});// end each
}
    profileExist: function(fileSystem) {
// if profile.json exist that means it's not the first time it's opened
}

    firstLaunch: function(fileSystem) {
// if profile.json does not exist that means it's  the first time it's opened so we do something different
},
    onFileFail: function(evt) {
// fallback if online files didn't get loaded
}
}

function startApp() {
// loads html tpl, backbone router start etc...
}

On Friday, May 17, 2013 3:30:55 PM UTC+11, Guillaume Bartolini wrote:

Cisse Mo

unread,
May 17, 2013, 9:22:09 PM5/17/13
to phon...@googlegroups.com


Sent from my iPhone

Guillaume Bartolini

unread,
May 21, 2013, 4:06:32 PM5/21/13
to phon...@googlegroups.com
Ok i got it. When creating a single folder addind or not adding files to it changes nothing, the folder gets created. But if creating a folder structure ( so more than 1 folder deep ) you must had files inside or the folders will not get created. 
This is why when offline my filders didnt show up. 

Sent from my iPhone
--
-- You received this message because you are subscribed to the Google
Groups "phonegap" group.
To post to this group, send email to phon...@googlegroups.com
To unsubscribe from this group, send email to
phonegap+u...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/phonegap?hl=en?hl=en
 
For more info on PhoneGap or to download the code go to www.phonegap.com
 
To compile in the cloud, check out build.phonegap.com
---
You received this message because you are subscribed to a topic in the Google Groups "phonegap" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/phonegap/wwr06A3Bscs/unsubscribe?hl=en-US.
To unsubscribe from this group and all its topics, send an email to phonegap+u...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages