How to group files according to formats in folder structure in iOS app? - iphone

I'm trying to make an app where I can group different files in their respective folders from two accessed servers. For example all pictures from two servers should be in Picture folder and all music files in Music folder of the app.
As I have to access all the files from the server how could I group all the files in above mentioned folders.
Any suggestions how to initiate from above situation

Generally interactions with the app's sanboxed file system are done via the NSFileManager class.
http://developer.apple.com/library/ios/#documentation/Cocoa/Reference/Foundation/Classes/NSFileManager_Class/Reference/Reference.html
That class allows you to move, copy, delete, etc... You'll likely want to use it to first create your two directories, then use it to save files into those directories as needed.

Related

How can I exclude a file from iTunes file sharing?

iTunes file sharing works by exposing all the files in /Documents
But I would want to explicitly exclude certain files. Is this possible?
UPDATED:
Specifically, one of my ad network SDK is storing a mraid.js in Documents.
If you don't want a file shared, don't store it in the Documents folder. Use the Application Support folder for example.
Another option is that iTunes won't show any files or folders from the Documents folder that start with a dot. You could rename the files you don't want to share with a dot or put them in a subfolder whose name begins with a dot.
Try looking at This Question. Also, depending on what you are storing, you can try using the NSUserDefaults instead.
There is no way to exclude files from File Sharing.
The files you need to share should be put under Documents directory and the files which you don't want to share should be kept in other directories. It'll solve the issue.

UIFileSharingEnabled use folders

I want to allow users add files to the application document folder, so I used the iTunes file sharing. The problem is they can only add single files with a flat structure. I want to drag and drop whole folder (even with sub folders) and keep the structure.
Questions I have:
is it possible with iTunes file sharing?
if not, is there an open source project that helps me with writing a pc side app that talks to the iPhone side app and pushes the files into it?
No you can't add Folder's/sub folders, iTunes will show just the files in the documents root. I think the only way to do that is to add it as zip file and you extract it in your app.
Maybe CocoaHTTPServer will help you.

How can we make a nested directory in resource folder to put the xmls with same name?

How can we make a nested directory in resource folder to put the xmls with same name for different folders.And how we can read it using path in iphone app programatically?
Actually i want to make like resource>a>b>some.xml
again in resource like resource>f>g>some.xml
and so on...how ever both xml is containing different data in it.and also tell me the way how we can read it in iphone application.
You cannot use the same filename, even if they resides in different folders.
Instead, as a workaround, you can name the files like:
a_b_some.xml
f_g_some.xml
you can create a folder structure on your system and then directly add the folder to your XCode Project under resources by drag-drop.
this folder must display in BLUE color (physical grouping in folder on disk) rather than YELLOW (logical grouping in project only) just like native folders on mac. like this you can put same file in different folder hierarchy without any problems.
you need to create a absolute path to your file whenever you want its access your file [NSBundle pathForResource:] will not work in this case as it does not have access to your custom folder hierarchy.
best of luck.

Is it possible to limit iOS file sharing functionality to a subfolder in the documents directory?

My image editing app is saving some important data in the documents directory. In a tutorial I was reading this:
iTunes will then display anything you
save to the Documents directory in
your app to the user, when they go to
the “Apps” page in iTunes and scroll
to the bottom:
I have a subfolder called userImages and it would be clever to restrict file sharing only to that folder and not to everything in documents. Otherwise the user would accidently (or on purpose) mess around with files that the app depends on to work properly. This would be bad.
Is there a way to restrict it to a subdirectory in documents?
No, what you should do instead is store anything you do not want users seeing in the "Library" directory for the app. Check here for a list of places you can store data:
How can I get a writable path on the iPhone?

(iphone) How to store images in directory structure (vs flat documents directory) and related questions

I'm looking for a good way to manage many image files in my app.
When the number of images to maintain gets large, it seems vital to have a directory structure to hold them.(to organize images and to support duplicate image names)
Since normal way of storing images in documents directory(by adding images to xcode's resource folder) doesn't seem to support directory structure,
I probably need to use something called bundle.
Here are questions.
It's not clear to me what's the difference between "documents
directory" and "bundle". Are they
just names to specify directory path
inside an iphone application? Since
documents directory doesn't support
directory structure, I guess it's not
a regular file path in iOS? (I'm
looking for a definition or overview
description on those two terms enough
to help answering the following
questions)
How do I create a tree structure directory to store resources?
How do I add files to the created directory?
What is the step (probably in xcode) to add new files to the
directory as project grows? note:
question 3 deals with initial set up,
4 deals with update.
What happens to files under documents directory and bundle when
user updates the app? Since many
applications store user data
somewhere, there must be a way of
updating an app without wiping out the
saved user data. ie. How does
"documents directory" and "bundle"
behave in update situation?
So called "resource bundle" refers to the "bundle" used in above
questions?
Thank you.
Your app is a "bundle". It's represented by an NSBundle object. On iOS, this is the only bundle you are allowed to use; you can't create another bundle and import it into your app.
However, you can add a subdirectory to your app's bundle. In Xcode 4, select your project in the navigator and click on the Build Phases tab. Add a new build phase (bottom right), Copy Files. Move it up just below Copy Bundle Resources, and rename it something meaningful ("copy interface images", or something). You'll notice you've got a Subpath field there - that's your directory in your bundle. Drag the files you want in that subdirectory on to this build phase, and then you can access them through the normal methods in NSBundle, UIImage, NSData and so on.
Wish it was easier? Me too.