I have been coding on my iMac for a bit now to learn objective-c (which I am seriously still a newb at, it’s like me writing a term paper in German). Well, anyway, I have started to gather some tips that took me a while to figure out so I figured I would share my findings. Since I am using xCode 5.x most of the search results are pre version 5 and don’t help a lot. Google and the iOS developer library have been invaluable along with all of the sample applications. So if you read anything I could do easier/better please let me know.
The first part of accepting files in your iOS application is registering the file types you are wanting to open within your application. This allows your application to show up in the open dialog when you hold down on an attachment in an application like mail:
This was a little bit of a challenge because the new UI in xCode 5 does a lot of this for you. You no longer have to edit XML, you can just use the properties dialog to register for the file type. Here is what I did to register my application to open ZIP files:
You can get a full list of supported System-Declared Uniform Type Identifiers here. Once you figure out what files your application will use, the next step is to code the retrieval of that file in your application.
Like any newb, I learned a lot of things the hard way – I should have probably bought a book but I figured I would struggle through it because I learn better. What I found out is the iOS sets up its file system in a sandbox manner. Meaning applications have their own “space” in the storage device. It is setup very similar to user directories in Linux. Each application
When you gesture to open a file with your application it is actually copied to the Documents/Inbox directory under your . So one lesson I learned is to clean this puppy out after processing the file because, for instance, if you keep opening the file my-archive.zip it actually keeps getting copied to the Inbox folder and you could have a situation where you keep storing new copies:
After debugging a little I noticed that while testing my application I ended up taking up over 300MB of space with many copies of the file. This is basically a “memory leak” if the application does not delete these files appropriately.