views:

49

answers:

3

In my applications i hav a terms and conditions view describing terms to use when user selects agree he will go to sign in page otherwise not ,it must be visible to user at first time when application launched in his mobile after that it has to start up with sign in view

how can i do this ... any ideas appreciated....

A: 

You can do this using NSUserDefaults.

In the applicationDidFinishLaunching method, look for the presence of a BOOL key that you place in NSUserDefaults. If it does not exist, run your code to show the terms and conditions, then set that variable to true in NSUserDefaults so it does exist next launch.

pkananen
i am new to iphone development ,so can u give me an idea about user Defaults
lak in iphone
Actually, he should first present the terms and conditions view and wait for the user to agree before setting the value. Otherwise, simple closing of the app (due to incoming call) might be considered by the app as an acceptance, as on the next run the value will be there.
Franci Penov
That is a good point.
pkananen
+2  A: 

You can use a flag on your NSUserDefaults. On your applicationDidFinishLaunch you would check for the flag, and if not present, show the disclaimer AND update the flag.

The code would be similar to this:

BOOL disclaimerAccepted = [[NSUserDefaults standardUserDefaults] boolForKey:@"disclaimerAccepted"];
if (!disclaimerAccepted) {
    [window addSubview:disclaimerView];
    [[NSUserDefaults standardUserDefaults] synchronize];
}

When the user clicks the accept button, you can update the setting as follows:

[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"disclaimerAccepted"];

As @mvds suggests in the comments, it may be a good idea to store a number or string instead of a bool value, containing your app's version number. That way, you can force users to re-accept the terms and conditions when you update your app.

pgb
Since this is terms and conditions, the flag should be update _after_ the user clicked on the Accept button, nor immediately after the view was shown.
Franci Penov
I wouldn't make it BOOL, but an integer or string instead, setting the *version* of the disclaimer that has been accepted. When you update your app, you may want to update the disclaimer. Since settings are preserved, you would otherwise have to use a different key everytime which gets messy.
mvds
I agree with both of you, thank you!
pgb
i want to show next view when user press accept button already
lak in iphone
how to save integer using ns user defaults
lak in iphone
A: 

On your app startup use NSUserDefaults to check for the presence of a user setting with a name of your choosing (for example firstRunFinished or userAgrredToTerms). if that setting is present and has value of true (or YES), you proceed normally. if the setting is missing, or is present but has a value of false (or NO), push your terms and conditions view as a modal view at the top of your main controller view stack.

Franci Penov