iPhone save game state - iphone

I'm implementing a save game feature to my game, so I'm looking for the best way to store the saved game.
Since I'm using C++ everywhere it's possible, I can't use NSKeyedArchiver to store the state of the game.
I am thinking in saving the state manually in a file, so I have a questions about that:
In which subfolder of apphome should I save that file? Looking into the iOS Programming Guide I didn't found a folder that perfeclty fit that need. Should I create a custom subfolder in Library or am I missing something?
Thanks in advance

Write the file into the Documents directory (NSDocumentDirectory). Thats the path to save your stuff, you can alter its content in any way by eg. adding subfolders for your save games or whatever.
DON'T save it inside the library folder!

Related

How to store data localy in swift osx app?

I'm working on my first osx App and I want to save arrays of objects that I've created on a "project file" like you do in any program when using the "save" button.
I have been looking different ways to do it, Core Data, Document based app, but, I'm not sure how it works any of them to choose the best option for my app.
I want to save arrays of objects that have inside more arrays and other strings and doubles that contain information of the app that the user added. ( It can be a lot of data ) So for that reason I think Userdefault is not a good idea.
I also want to make the app able to open one of this projects saved.
So, could you help me to find which is the best way to do it?
I can suggest you to read iOS FileSystem Overview.
You must use the Data container to locate your local files. For this, you have to locate the NSDocumentDirectory with the NSUserDomainMask (call to NSSearchPathForDirectoriesInDomains) and use standard NSFileManager class.

Valid file types for iCloud?

I find many similar question but i didn't get solution for this.
Is it possible to upload some file like image, document, zip file to upload on iCloud programmatically?
See table 4-1 in the documentation:
How do you manage the data? Manage files and directores using the
NSFileManager class. Open, close, read, and write files using standard
file system routines.
So if you can create a file, you can store it in iCloud. But remember there's a finite, relatively small amount of space available.
iCloud can handle all kinds of files. So if you want rot use an obscure file format or invent your own, go for it. It only can to be converted into a byte stream/NSData, but then again, what isn't?
Check this tutorial walkthrough app. It shows how to create, modify and delete files for iCloud.
http://github.com/lichtschlag/iCloudPlayground

Does updating your application delete files?

I wrote a game that I plan on updating soon. The game generates a scoreboard when the application starts, if there is no scoreboard file present.
If people update to my latest version, will the scoreboard file (that's generated by the code itself, not a file that comes preloaded in the app) be deleted?
If so, is there any way to avoid this without any coding previously required?
The updated version of your app will simply replace the existing version's bundle - any files you've written to your app's document area will remain intact.
As such, you simply need to check for the presence of the file within your app's document area as per usual and write a "new" version if none exists.
If the file is within your applications bundle, it will be deleted. Files saved with Core Data and NSUserDefaults will not. I've never personally written a file to the disk, so I don't know where the default write point is. You'll have to find this out yourself.
Happy coding,
Zane

Importing huge music files into database

We have very huge music files in mp3 formats (very huge more than 1,000,000) and would like to import all these songs into the DB of an application we are developing. Is there any easy method to import such huge files at once. Kindly let me know
Why not just use a filesystem for them - that's what file systems are designed for? Index the filenames in a normalised DB.
Yes, there is
Take a look at how has Apple solved that problem. Go to the iTunes_control folder on the iPod. You'll see that there's a Music sub folder with dozens of folders named f00, f01, ... f50 (50 is arbitrarily big number). Every file has been renamed to a filename that looks like a hash value.
Use the file system to store the files. In the database store the path to the file on the file system together with the mp3 metadata information (artist, name, album, composer, etc) and provide search capabilities over it.
You don't want to store music into the database. Store some kind of URLs to music into the database, with all the metadata you want to keep, and store music into folders on various servers. I am author of radio automation software that used this scheme and we never looked back at our decision.
Main reason for that is that you don't want anyone to be dependent on some database API to extract the music.

Managing resources and keeping them out of version control

My iPhone app will have a map with about 10 points on it. It will play sound files based on the proximity to those points.
What's the best way of managing these resources?
Coordinates and accompanying sound file could be stored in a plist, as an array of dicts with latitude, longitude and file name. Then the sound files could be stored separately.
The plist and sound files should not be version controlled.
How much, and what, should happen compile-time, and run-time? How do I manage this?
The end result should be an app binary with the sound files embedded and the records stored in core data. Doing stuff on first launch of app is also OK.
I think my question could be rephrased to: how do I manage resources programatically, at build time?
Add the sounds folder as a 'folder reference'. Then any files you add to that folder will be included in your bundle. Right click on your project->Add Existing Files then choose 'Create Folder References'