How can I show a view on the first launch only?

后端 未结 4 1737
我在风中等你
我在风中等你 2020-12-01 08:42

I built an application using Xcode 4.5 with storyboards. The first time the app launches I want the initial view controller to appear with terms and conditions that must be

4条回答
  •  甜味超标
    2020-12-01 09:13

    You put in in your AppDelegate:

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {  
    
    //first-time ever defaults check and set
    if([[NSUserDefaults standardUserDefaults] boolForKey:@"TermsAccepted"]!=YES)
    {
        [[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"TermsAccepted"];
    }
    

    Then you implement in your rootViewController the terms and conditions and a way to accept it. You will have to check if the terms are accepted, for example like this:

    if ([[NSUserDefaults standardUserDefaults] boolForKey:@"TermsAccepted"]){
        //proceed with app normally
    }
    else{
    //show terms
    }
    

    When accepted, the following code will change the default settings:

     if(termsaccepted){
        [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"TermsAccepted"];
    }
    

提交回复
热议问题