How to Localize sound files - ios

I have sounds in my app, which are appropriate for different languages.
How can i load the correct file depending on locale without checking it manually ?

You need to add the files to Xcode and then localize them in the right hand side panel:
You then have a list of localizations:
Then the bundle will pull out the correct file.
[[NSBundle mainBundle] pathForResource:#"audio" ofType:#"mp3"];

If you have properly localized the files in your project, then you'll 'automatically' get the correctly localized path by calling [[NSBundle mainBundle] pathForResource:resourcePath ofType:type];

Related

Access pre-existing database(read only) from iOS bundle

I have pre-created database stored in a folder inside my bundle. Can I access it directly from that folder without copying to Document folder?. I don't want to write anything to Db. Only want to read some data. I am using FMDB framework also.
You can get the path to your database using:
NSString *path = [[NSBundle mainBundle] pathForResource:#"someDB" ofType:#"sqlite"];
Change the parameters to match your database. And then provide that path to your framework so you can access it.

is their a way to bundle sqlite database file with os x application? for both to be one file

I tried sqlite FMDB but it must store database into separate file I want solution that the database file is the same executable file ie they are bundled together into one app please help
Here's how to do it: create database with a file handle for the file system produced in the traditional way (NSSearchPathForDirectoriesInDomains and stringByAppendingPathComponent: #"mydb.sql").
Sounds like you've got that done. Drag the resulting file into your app. Once in your app bundle, the way to get at the file is like this (using the filename I made up above):
NSString *fileName = [[NSBundle mainBundle] pathForResource:#"mydb" ofType:#"sql"];
// or whatever you called the file in your bundle, use ofType: as the filename's extension
That should suffice as input to the FMDB package.

NSHomeDirectory - [ NSBundle mainbundle ]

what is the difference between nshomedirectory and [nsbundle mainbundle]
how can i copy a file to the nshomedirectory / documents file from my mac ?
which one i need to choose for store .sqlite file ?
when and why i need to choose [nsbundle mainbundle] to some things ?
i found this site http://www.ios-developer.net/iphone-ipad-programmer/development/file-saving-and-loading/where-to-store-files but it didn't told me the difference.
[NSBundle mainBundle];
taken from apple site;
in general, the main bundle corresponds to an application file package or application wrapper: a directory that bears the name of the application and is marked by a “.app” extension.
[[NSBundle mainBundle] resourcePath];
This method returns the appropriate path for modern application and framework bundles. This method may not return a path for non-standard bundle formats or for some older bundle formats.
NSHomeDirectory();
This outputs the users home directory for example /Users/someuser/
in iOS, the home directory is the application’s sandbox directory. In OS X, it is the application’s sandbox directory or the current user’s home directory (if the application is not in a sandbox)
To answer your question:
NSBundle mainbundle refers to the location of the *.app file in the filesystem where as NSHomeDirectory points to the users home directory and nothing to do with the location of your app.
I also added the [[NSBundle mainBundle] resourcePath]; option as this may be what your looking for.
have a look through NSBundle on the apple dev site for more info,
NSBundle Class reference
Sorry I cant help with your other query, ive got no experience using sqlite.

Get contents of directory from main bundle

I am including a directory full of files in my app. I looked through the NSBundle docs, but I can't seem find out how to get the URL to this directory. I'm trying to use the main bundle object.
I have a directory "defaultImages" under a directory "Resources" in xCode. I have confirmed that these are being copied to the device, how do I get the URL to them?
Specifically, the following does not work.
[[NSBundle mainBundle]:URLForResource:#"defaultImages" withExtension:#"" subdirectory:#"Resources"];
Try
NSString *filepath = [[NSBundle mainBundle] pathForResource:#"defaultImages" ofType:#"footype"];
Apparently NSBundle will not locate a directory for you. My solution was to put the contents of the directory inside a bundle, via How to make an iOS asset bundle?. I then added that bundle to my main application bundle.

File operation not working on device

What could make a file operation that is working well on the simulator, to not be working on an iOS device?
When using [NSBundle mainBundle], and the file is found by FileManager, what could be the different reasons for adjacent file operations to have different outcome?
I am noticing this sometimes, and just want to get an idea of what to think about when this happens.
Seems like you are trying to read a file in your application bundle. You may get its path by code:
NSString *filePath = [[NSBundle mainBundle] pathForResource:#"fileName" ofType:#"ext"];
//Then you can use NSFileManager to read/copy it
All files in application bundle are readonly. You may get more information from here:
http://developer.apple.com/library/ios/#documentation/CoreFoundation/Conceptual/CFBundles/AccessingaBundlesContents/AccessingaBundlesContents.html#//apple_ref/doc/uid/10000123i-CH104-SW8
As #Aadhira said in the comment above, the simulator stores its files inside a bunch of folders on your mac, not in some sort of simulated main bundle/docs directory sandbox.
In order to get a static file from your main bundle you must create a path starting from [NSBundle mainBundle] and add path components onto it.

Resources