How can I detect the first launch of my application and run a View Controller just onc e(for example: "Create your user profile and save it") ? I am using Xcode 5.1/ I would appreciate any help or guidance. Thanks, Tudor
Asked
Active
Viewed 1,026 times
0
-
You need to tell us what you have tried so far. If you haven't tried anything, people won't help you here. – OMGtechy Jul 26 '14 at 14:52
-
I've tried the NSUserDefault method and set a BOOL for this, but i didn't notice any difference. I would like to start my app with "ProfilViewController" wich contain (.m with my -ibaction buttons, labels etc). I need to copy something in my CCAppDelegate? – Ionuţ Tudor Urdéş Jul 26 '14 at 15:02
-
possible duplicate of [How to detect first time app launch on an iPhone](http://stackoverflow.com/questions/9964371/how-to-detect-first-time-app-launch-on-an-iphone) – Guntis Treulands Jul 26 '14 at 15:20
3 Answers
2
You just need to store a simple persistent value the first time your app launches. I've made it like this:
+ (BOOL)firstLaunch {
static BOOL result;
if ([[NSUserDefaults standardUserDefaults] boolForKey:@"hasLaunchedOnce"]) {
result = NO;
} else {
[[NSUserDefaults standardUserDefaults] setBool:YES
forKey:@"hasLaunchedOnce"];
[[NSUserDefaults standardUserDefaults] synchronize];
result = YES;
}
return result;
}

dibi
- 3,257
- 4
- 24
- 31
0
Try using NSUserDefault to detect first launch and call the required viewController from viewDidLoad method or you can also do this directly from didFinishLaunchingWithOptions in AppDelegate.m
use the below code to call the required viewController when bool value is true(i.e, first launch)
UIViewController * vc = [[UIViewController alloc] init];
[self presentViewController:vc animated:YES completion:nil];
Hope this helps you. Happy coding!

bachman
- 690
- 7
- 22
-
when i write [self ProfilViewController:vc animated:Yes completion:nil]; i receive an error : No visible @interface for "ProfilViewControole" declares the selector ProfileViewController – Ionuţ Tudor Urdéş Jul 26 '14 at 21:50
-
-
@IonuţTudorUrdéş mh I think you should start with a basic iOS/Objective C tutorial. – dibi Jul 27 '14 at 06:40
-
-
@IonuţTudorUrdéş Yeah no problem, we've all started once. But I mean some questions are really obsolete if one starts with reading the basics instead of asking it on SO :) – dibi Jul 27 '14 at 18:13
-
-
you are welcome! if you find my answer working, I would be even more happy if you could up rate or mark my answer correct ;) – bachman Jul 28 '14 at 07:14