App Settings change: 2 synchronizes for StandardUserDefaults necessary? - iphone

I am changing app settings within my iPhone application.
Strangely, I have to do 2 synchronize commands with StandardUserDefaults to make my changes to be reflected in the app settings.
Secondly, when I change my "preferred user language" within my iPhone application, I do have to start my app twice for the language change.
What's the reason for that?
Is there a way to dump the StandardUserDefaults and to see all the settings stored there?
Thanks for your help!

Is there a way to dump the StandardUserDefaults and to see all the settings stored there?
Yes, that is pretty easy to do.
The NSUserDefaults are stored in a plist file located in your app's sandboxed environment inside the Library folder.
For checking this on the simulator, have a look at
~/Library/Application Support/iPhone
Simulator/5.0/Applications/[hashed app
identifier]/Library/Preferences/[application bundle identifier].plist
Note that you will have to replace the values in brackets to find your specific app. Also note that this path works for the iOS5.0 environment - for others, you will have to replace the 5.0 with whatever system version you are working with.

Related

sqlite file path created using iOS - UIWebView

In my application we are currently using sqlite from UIWebView to store user preferences and details. Now we are moving this functionality in native Objective-C code, and want to preserve those defaults when application will be updated.
I am thinking of accessing .sqlite file from Objective-C code and transfer those preferences in NSUserDefaults. Where can I look for .sqlite files created by UIWebView, whats the default location ?
If you're on the simulator, db files are here:
/Users/<your-user>/Library/Application\ Support/iPhone\ Simulator/User/Applications/<your-app-id>/Library/WebKit/Databases/file__0/<database-name>
On the device, try:
/var/mobile/Applications/<your-app-id>/Library/WebKit/Databases/file__0/<database-name>

InAppSettingKit custom bundle is not recognized on device

I set up InAppSettingsKit and wish to have only certain volatile settings available from within the app. These would not be the same as what is found in settings.app from springboard. I added a bundle, InAppSettings.Bundle and created the appropriate plist files. It works as expected in the simulator but acts as though my new bundle does not exist on the device. The device shows only the same as the settings.app properties in settings.bundle/ root.plist.
How do I get the new bundle into users' devices without deleting and reinstalling the app?
In this case, it was a "case" of developer error. Apparently the case of the characters in the name of a file are not specific in the simulator. The files in my bundle were not correctly named. I had root.inApp.plist when it should have been Root.inApp.plist. Worked in simulator,not on the device.
Once I realized this and renamed the file, the device read and displayed the correct file as intended.
That was a waste of about 5 hours chasing my tale. I Hope this info helps someone avoid this same annoying oversight.

Are NSUserDefaults global to the entire device or just the app

I have a NSUserDefault which just stores whether the db has been configured or not. However after deleting the app and re-installing the nsuserdefault seems to remain?
NSString *dbIsConfigured = [[NSUserDefaults standardUserDefaults] stringForKey:#"dbIsConfigured"];
It is local for the app only. The other apps cannot be able to access that.
From Apple documentation for NSUserDefaults:
Sandbox Considerations
A sandboxed app cannot access or modify the preferences for any other app. (For example, if you add another app's domain using the addSuiteNamed: method, you do not gain access to that app's preferences.)
Attempting to access or modify with another app's preferences does not result in an error, but when you do, Mac OS X actually reads and writes files located within your app's container, rather than the actual preference files for the other application.

IPhone App Settings: Settings.bundle vs plist file?

I'm a bit confused. I'd like to implement some simple settings for my app. I was thinking of just creating a simple plist file. But now I see that there's something called "Settings.bundle" (that also has a plist in there but some other stuff too).
What I'm wondering, which one should I use? (I'm looking for the easiest way)
Thanks!!
I would suggest looking into NSUserDefaults to store basic app settings.
The settings bundle is for having settings that show up in the system Settings.app. You can use a plist (or easier, NSUserDefaults, which handles the plist for you) to store settings that you change within the app itself.
See the Displaying Application Settings section in the iOS Application Programming Guide.

Reading a file from a hard drive in iPhone simulator

Is it possible to read a file (from my normal file system) into a iPhone App running on the iPhone Simulator?
I understand that the iPhone itself has not got a (user accessible) file system but this is simply for testing and will only ever be run in the simulator.
The file will be a text file that can be edited while the application is running, it will be read every-time a method is called.
Yes, you can, and it doesn't matter where it is. Just give it an absolute path name when you load it (Xcode won't recognize a different working directory when running the simulator).
Yes, you can if your file is within your app folder
~/Library/Application Support/iPhone Simulator/User/Applications/ [your app folder] /Documents
No. Your app is running in its own sandbox on the phone. It's not allowed to read or write outside of it.
Edit: I think CiNN is correct. As long as your code stays on the simulator, you shouldn't have problems working with a file on your local drive.
I personally think that the easiest way would be to enter "file:///" in Safari within the simulator, if thats what your looking for.
It should also be noted that you can do this in reverse -- you can grab the files off your hard drive that your application created in the simulator. This is a good way to check out your results (data, images, whatever) without having to build a data "viewer" into the application.
FYI 'newer' sds versions will do this... Search for iPad and you will find it. (for obvious reasons I cannot give more details here) good luck.