How to embed custom resources and folders in iOS applications - ios

I have an iOS application that embeds a native C binary bundled as a static library. This binary was initially designed to work on "regular" computers and relies on some specific folder layout, something like:
myapp
- images
- big
- thumbnails
- templates
- sounds
For the binary to work properly, I need to keep this layout as it is. I haven't done much iOS development and maybe this is a trivial question, but how can I replicate this folder layout within my iOS application (and how to get its absolute path within the application) ?

Every app has a sandbox with a set of folders that you could use. Would your app still function if they were in say the Documents or Library folder?
NSString *documentsDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *libraryDir = [NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES) objectAtIndex:0];
There is also /tmp and /caches, but probably these aren't what you're looking for. I believe both of the above survive updates/sync.

Related

iOS: Is this the proper way to setup a database location under the application support folder?

I have a sql file that needs to be stored in my App. A user on this site recommend me to store it underneath the Application Support folder. This is the path directory that I am using with my fmDatabase library.
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES);
NSString *applicationSupportDirectory = [paths firstObject];
self.dataBasePath = [applicationSupportDirectory stringByAppendingString:#"Email.sqlite"];
self.fmDataBase = [FMDatabase databaseWithPath:self.dataBasePath];
Everything seems to be working fine. However, I am a little nervous that I may be doing something wrong. I am using the Application Support directory because I don't want the OS or an update to interfere with the Database. I would use the document directory ,but my App supports file share so the user can mess it up.
(application_home)/Library path is a place where you can create custom subdirectories for files you want backed up but not exposed to the user.
create a directory such as (application_home)/Library/Database and save files there.
for mac os x with sqlite The convention is to store it in the Application Support folder .
i.e. in ~/Library/Application Support/YourAppNam*/database.db
I think the data will be saved on the Application Support Folder in Mac platform, for iOS, the default is xxx/Library.
I don't see any dangerous element on this, because you can save to different folder as long as you can load it from right path.

How private document directory can be set in iOS8 as storage provider application extension is making default Document directory Shared?

My iOS app is running all well & good till iOS7. But as soon as I run on iOS8 beta version it crashed.
When I tried to investigate I found that in iOS8 Storage provider changed the path for the default document Directory.
How can I set it to default Document directory to keep the applications private data Safe
How are you getting the path of the Documents directory? If you use the recommended API (like below) it should translate over to ios8 without any problems.
NSString *docsDir = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0];
Also, not clear what you mean by "keeping private data safe" -- any data you write to the Documents directory is not accessible by any other app.

How to get files into library directory for iphone device testing

I have tested my app on the ios simulator and using the following code:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *dictdir = [documentsDirectory stringByAppendingPathComponent:#"dict.plist"];
NSLog(dict);
I found the path in which to save my file, dict.plist so that it can be used later by the app.
I am now testing on my device and the place where I am intending to store my .plist file is
var/mobile/Applications/......./Documents/freq.plist
First of all, I know that non-user data is meant to be saved in the library folder, so how do I change my code so that the path is leading to the ..../library/ directory?
And how do I actually put my file in this directory? Right now using the 'organizer', I managed to get the file into the app sandbox, but not in a particular folder.
The same code will get the correct path on the device and simulator, that's what it is meant for. However, if you want to copy it, you have to include it in your bundle, or download it from the internet. You can't just copy it with the finder. For copying from the bundle, use the the function – copyItemAtURL:toURL:error:. Downloading is a bit more complicated and is probably better suited for a separate question.
Just change NSDocumentDirectory to NSLibraryDirectory

Storing information ios SDK

So I have lots of application data for my application. However, This data does not necessarily need to be backed up to itunes.
Where would be the best place to store it?
You can put it in the caches directory
NSArray* cachePathArray = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
NSString* cachePath = [cachePathArray lastObject];
or the temporary directory
NSTemporaryDirectory()
Note that there have been some concerns with iOS 5 as it sometimes clears the caches directory (which previous versions of iOS didn't, current iOS 5.0.1 in beta at the moment aims to solve this). You need to be careful when storing large files to the documents folder in iOS 5
NSArray* documentPathArray = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString* documentPath = [documentPathArray lastObject];
because of big iCloud sync times.

How can I retrieve files from an iPad development tool app?

I'm not sure how best to word the Title of this, so if someone can suggest a better one, please feel free to edit.
I'm writing an app for iPad that requires me to create some of the app data files with the iPad itself during development, i.e. a tool I am building with the iPad will be used by the developers themselves to create sample files that can be played by the app itself.
My question is, how can I best do this? I tried writing files to a local dir on my mac while the iPad was connected but I get a crash. Ideally if there is some way for me to generate an output file on my iPad and get it transferred to my Mac while my dev build is running, I'd do that.
Suggestions?
It looks like the trick it to use Apple's File Sharing to place files in a folder accessible through iTunes, explained here:
Standard Application Behaviors
The gist is to add a UIFileSharingEnabled plist key set to true and then query the Documents folder for your application like so:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];

Resources