Reputation: 165
I want to add a screen to my app that will be only displayed the first time when the app is launched. How do I do that? Thanks in advance. Cheers, Alex
Upvotes: 1
Views: 4208
Reputation: 2836
I think you are asking for splash screen-an image displayed at app start-up
Here is a nice tutorial about this:
iPhone Tutorial for Creating a Splash Screen
Upvotes: 1
Reputation: 1039
If you want the code, here's what I use;
#define kAppHasRunBeforeKey @"appFirstTimeRun"
if (![[[NSUserDefaults standardUserDefaults] valueForKey:kAppHasRunBeforeKey] boolValue]) {
//put your welcome code here
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:kAppHasRunBeforeKey];
}
That will ensure that the welcome code is only run the first time your app runs across this code. Put this in your main view controller's viewDidLoad
method and add your own welcome code.
Upvotes: 4
Reputation: 10393
You can keep a variable in NSUserDefaults. In your first view controller's viewDidLoad
method check that variable and create the welcome screen and add it as a subview to the controller's view. Once its displayed you set the variable to 1 in NSUserDefaults
.
This will display that screen first time when it's launched. If app is deleted then the next install will have the NSUserDefaults
value cleared off. I hope this helps you.
If you dont get the documentation of NSUserDefaults
, which is fairly simple, drop a comment and I will write up a piece of code for you.
Upvotes: 11