开发者

iPhone first time application ran and config files

开发者 https://www.devze.com 2022-12-28 17:58 出处:网络
I\'m developing an iPhone application and I want to know when it is the first time the application is executed. I want to check some extended permissions from facebook the first time.

I'm developing an iPhone application and I want to know when it is the first time the application is executed. I want to check some extended permissions from facebook the first time.

  1. How can I know that?

Another开发者_StackOverflow社区 way to solved this problem is to store the extended permissions granted in some configuration file. I don't want to make visible this file through app settings icon.

  1. How can I add some configuration files to store these permissions granted?


  1. The std way would be to check if there is a value in NSUserDefaults and if that value doesn't exist (such as on first run) then create the value so on the rest of the starts you will know its not first run.

  2. This is also a good candidate to use the NSUserDefaults and set key/value pares for each setting/permission you want.

Here's a quick tutorial on using NSUserDefaults.

Summary from that site for Saving:

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 perfect for saving app settings, and purchase history but if you are wanting to store much data then you should use another way.


Just write to a local file (xml or whatever). Check, first, for the existence of the file. If not there this is the first run - otherwise just read the file.

0

精彩评论

暂无评论...
验证码 换一张
取 消