High level process of extracting images from a container - iphone

Right, this is the problem I have a container (rar,zip) which contains images png's tiffs bmps or jpegs in an order.
The file extension isnt zip or rar though but uses the same compression.
I want to pull out a list of images contained within the file in the numerical order, then depending on the user decision go to the image selected.
I'm not after any code just the high level thought process/logic of how this can be achieved and how it could be achieved on iphone OS.
From what i know of iphone OS it uses a kind of sandbox environment so how would this effect the process as well.
Thanks

You can include the libz framework in your project and write some C to manage zipped data. Or you can use Objective-C wrapper classes others have written.
Your application resides in its own sandbox. You can include zip files in the "bundle", i.e. add them to your project, and copy them to the application's Documents folder to work with them. Or you can copy archived data over the network to the application's Documents folder if you don't want to include files in your project.
I don't think the extension matters so much as the data being in the format you expect it to be.
Everything I wrote above is for zip-ped files. If you're working with rar-formatted archives, you'll need to look at making a static library for the iPhone, perhaps from the UnRAR source code.

Related

iphone embedding images in the executable file

When releasing to the application store someone wrote in an offhand comment that you need to avoid embedding your images into the executable.
How do you do that?
I've seen code in various books that suggests encoding images as C byte array constants in the source code, and I can say that that's definitely a bad idea for reasons ranging from inefficient pixel formats to unsalvageable memory. That would qualify as "in the executable file" in a way that bundle resources don't, since bundle resources are packaged alongside the executable rather than within it.
I am not sure if I get you correctly, but maybe he meant accidentally adding image files to the Compile Sources category in your build target? This usually does not happen with images, but i have seen it happening with js files.
Perhaps they meant that you should only include images in the bundle that are essential.
The bundle is essentially read-only so you cannot remove an image from the device that is in the bundle. Therefore placing lots of example images that you expect a user to remove/not want is not a good idea because when the user deletes the images from inside your app no space on the device will be reclaimed.
Of course it is fine to place images in the bundle just make sure that they are required and are not taking up unnecessary space that the user cannot reclaim.

Storing Large Number Of audio resource

I'm working on a iphone application project in which, i have around 500(250mb) audio files.
When i got them from studio they were in wav format, I converted them to caf(35mb).
is there any other way/format i can compress them ?
dumping 500 audio files to iphone app resource will be good?
any suggestions?
In Storm Sim I did a folder reference for the audio samples with the files structured inside subfolders so I could keep them organized in a somewhat sane way.
Instead of using the standard get resource calls I just ask for the app's main bundle directory and the referenced folder is inside the main app folder with the appropriate subfolders under it.
Let me know if you need a code sample.

Xcode Project Size problem- 72 text files

I am new to iphone sdk and creating my first application so please be nice when answering my questions.
I have following questions
Q-1. I have created a simple iphone application (not a game app, no OPenGL). My program is running fine but total xcode project size is 9 mb. I found that my xcode project size is less than 2 mb without "class" and "build" folder.
Do we upload files of "build" and "class" folder when we submit our application?
I have checked that most of iphone applications are less than 2 mb in size so I think build folder is just for me to test the application.
Can someone give me the list of all files or folders (just extension) that we need to upload in order to submit an iphone application.
Q-2. there are around 72 text files (each is 2 KB in size) in my program. Program open a text file according the selected criteria. I have all 72 text files in resource folder. I am not using SQLite as I think it is not too much data and text files are small in size.
Can apple reject my application just because there 72 text files? Is it a common approach to use multiple text files instead of SQLite?
Q-3. Do I need to add zip and unzip my text files instead of opening them directly?
Q-4. some of my text files has following five words
"sex" "sexy" "kinky" "filthy" "dirty"
For example "You are so kinky" , "I love sex" etc.
Do I need to remove these words from my files? Will they be considered vulgar? Will my application be rejected because of these five words?
I have seen some iphone applications on apple's website which shows sex positions and use words like sex,sexy,kinky so I think it should not be a problem.
Do I need to add something like "mature content. Must be 18 years old" just because I am using these five words. I think these are pretty common words that are frequently used by young people.
Many of these questions can be answered more completely by Apple's help docs in the iOS developer center and iOS Provisioning Portal (https://developer.apple.com/devcenter/ios/index.action and https://developer.apple.com/ios/manage/distribution/index.action - you need to be logged in to view these links)
However, here are some quick answers:
1) The build and classes folder hold files during development. The build folder holds the binaries that are created every time you click 'Build' in Xcode, if you build for different targets, there will be multiple copies of your binary in this folder. It also contains various debugging and symbol files used by Xcode.
The classes folder contains all of the implementation (.m) and header files (.h) that you have in your project. This folder corresponds to the 'Classes' group in the file organizer when you open your project in Xcode.
When you submit an application to Apple, all you submit is the compiled binary (found in the appropriate folder in your 'build' folder). It is normal for your project folder to be many times bigger than the final binary you submit. For more info on the submission process, refer to the second link I posted above.
2) If you're persisting a lot of data, I would recommend using the built in SQLite database. It's very easy to use (Google will help you with this), and quite fast. Apple probably won't reject your app for storing a lot of data in flat text files, but you have no reason to. SQLite databases are much cleaner and easier to maintain than 72 flat files.
3) No. But you should still use SQLite, especially if you're saving enough data to these text files that they need to be compressed. Reading and parsing large text files can be much slower and more cumbersome than reading the same data from a database (databases are made to handle data storage like this).
4) Again, Apple probably won't reject you for this (of course, nobody actually knows why they reject apps, so it's always a bit of a crap shoot). When you submit your app, you can choose the rating level for it (sort of like game ratings, or movie ratings) so when people download it they are aware of the level of maturity of the content. One of the ratings is 17+, which you can use if you need. I believe Apple has a document outlining it's rating system in one of the links I posted above (or it's somewhere, it does exist).
First of all you don't need to upload build folder to upload but classes will be uploaded. you have to follow a process for uploading.
No problem at all you can upload even 1000 files, 72 is very small amount. but be careful that if you project is very heavy then it app will be crashed.
No need to zip the files.
you may use all of these words you may even use pornographic contents but they should not be copy righted of any body else. You don't need to remove them, when you will be uploading your application there will be an option "Application include adult contents" you just have to check that option.

(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.

Own data format for the iPhone

I would like to create my own data format for an iPhone app. The files should be similar structured as e.g. Apple's iWork files (.pages). That means, I have a folder with some files in it:
The file 'Juicy.fruit' contains:
Fruits
---> Apple.xml
---> Banana.xml
---> Pear.xml
---> PreviewPicture.png
This folder "Fruits" should be packed in a handy file 'Juicy.fruit'. Compression isn't necessary. How could I achieve this? I've discovered some open source ZIP-libraries. However, I would like to to build my own data format with the iPhones built-in libs (if possible).
Best regards,
Stefan
Okay, so there are three ways I am reading your question, here's my best guess on each one:
You want your .fruit files to be associated with your app via Safari/SMS/some network connection (aka when someone wants to download files made for your app or made by your app).
In this case, you can register a protocol for your app, as discussed here:
iPhone file extension app association
You want the iPhone to globally associate .fruit files with your app, in which case you want to look into Uniform Type Identifiers. Basically, you set up this association in your installer's info.plst file.
You want to know how you can go from having a folder with files in it to that folder being a single file (package) with your .fruit extension.
If that's the case, there are many options out there and I don't see a purpose in rolling your own. Both Microsoft and Adobe simply use a standard zip compression method and use their own extension (instead of .zip). If you drop any office 2007 document, such as docx or Adobe's experimental .pdfxml file into an archive utility (I like 7z, but any descent one will do), you will get a folder with several xml files, just like you're describing for your situation. (This is also how Java's jar file type works, fyi). So unless you have a great reason to avoid standard compression methods (I vote gzip), I would follow the industry lead on this one.
I can definitly appreciate the urge to go DIY at every level possible, but you're basically asking (if it's #3) how you can create your own packaging algorithm, and after reading how some of the most basic compression methods work, I would leave that one alone. Plus I really doubt that Apple has built in libraries for doing something that most people will just use standard methods for.
One last note:
If you are really gunning to do it from scratch (still suggest not), since your files are all XML, you could just create a new XML file that will act as a wrapper of sorts, and have each file go into that wrapper file. But this would be really redundant when it came time to unwrap, as it would have to load the whole file every time. But it would be something like:
Juicy.fruit --
<fruit-wrapper>
<fruit>
<apple>
... content from apple.xml
</apple>
</fruit>
<fruit>
<banana>
... content from banana.xml
</banana>
</fruit>
<fruit>
<pear>
... content from pear.xml
</pear>
</fruit>
<picture>
...URL-encoded binary of preview picture
</picture>
</fruit-wrapper>
But with this idea, you either have to choose to unpack it, and thus risk losing track of the files, overwriting some but not all, etc etc, or you always treat it like one big file, in which case, unlike with archives, you have to load all of the data each time to pull anything out, instead of just pulling the file you want from the archive.
But it could work, if you're determined.
Also, if you are interested, there is a transfer protocol intended specifically for XML over mobile called WBXML (Wap Binary XML). Not sure if it is still taken seriously, but if there is an iPhone library for it, you should research it.