First iPhone app app and configuration files
I am developing an iPhone application and I want to know when it is executed when the application is first launched. I want to test some advanced permissions from facebook for the first time.
- How can I know this?
Another way to solve this problem is to keep the extended permissions granted in some configuration file. I do not want to make this file visible through the application settings icon.
- How do I add some config files to store these permissions?
a source to share
-
The STD method should check if there is a value in NSUserDefaults, and if this value does not exist (for example, on the first run), then create a value, so on the rest of the beginnings you will not recognize it for the first run.
-
It is also a good candidate for using NSUserDefaults and setting options / values โโfor every option / resolution you want.
Here's a quick guide to using NSUserDefaults.
Summary from this site to save:
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
// saving an NSString
[prefs setObject:@"TextToSave" forKey:@"keyToLookupString"];
// saving an NSInteger
[prefs setInteger:42 forKey:@"integerKey"];
// saving a Double
[prefs setDouble:3.1415 forKey:@"doubleKey"];
// saving a Float
[prefs setFloat:1.2345678 forKey:@"floatKey"];
// This is suggested to synch prefs, but is not needed (I didn't put it in my tut)
[prefs synchronize];
Loading:
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
// getting an NSString
NSString *myString = [prefs stringForKey:@"keyToLookupString"];
// getting an NSInteger
NSInteger myInt = [prefs integerForKey:@"integerKey"];
// getting an Float
float myFloat = [prefs floatForKey:@"floatKey"];
NSUserDefaults is ideal for saving app preferences and purchase history, but if you want to store a lot of data, you must use a different method.
a source to share