Wednesday, 6 May 2015

How to setup first time launch of an iOS App

Hello reader's !
If you want to setup first time launch of an iOS app. Using this code the terms and conditions will appears or shown only the first time of app launch.
here is the code below.
I have two UIViewControllers (FirstViewController and AlreadyRunViewController). FirstViewController is for "Terms and Condition" page and if app is not running for first time then AlreadyRunViewController will appear .
So I have these files in my XCode :

Now, Go to to storyboard and give StoryBoard Id to "terms and condition" view controller.

Then go to your AppDelegate.m and paste below code :-
  1. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  2. // Override point for customization after application launch.
  3. if ([[self alreadyRunOrNot] isEqualToString:@"runalready"]) {
  4. NSLog(@"alreadyrun");
  5. }
  6. else
  7. {
  8. NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
  9. // saving user details to NSUserDefaults
  10. [prefs setObject:@"runalready" forKey:@"alreadyRunOrNot"];
  11. NSLog(@"run first time");
  12. UIStoryboard *story=[UIStoryboard storyboardWithName:@"Main" bundle:nil];
  13. FirstViewController *firstVC = [story instantiateViewControllerWithIdentifier:@"firstViewController"];
  14. self.window.rootViewController =firstVC;
  15. }
  16. return YES;
  17. }
Now storyboard will look like :-














For such more Blogs you can visit to http://findnerd.com/NerdDigest

No comments:

Post a Comment