Reputation: 3127
I am pushing out version 2 of my app and need a short walkthrough of the new features. I went through a tutorial and created my walkthrough in another app, with one UIViewController that is root view, a UIPageViewController which contains one UIView where I display my screens. It works as I want it.
Now I want to integrate this in my app. I can easily import my coding from the sample app.
I believe in the app delegate I will see if the user has ever been through the walkthrough, and if not, switch to the UIViewController that starts the walkthrough, and write to a default that the user has seen the walkthrough (so they don't need to see it again). I have a button in the walkthrough to go the main screen.
My partial code for the method "applicationdidFinishLaunchingWithOptions is below:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UIPageControl *pageControl = [UIPageControl appearance];
pageControl.pageIndicatorTintColor = [UIColor lightGrayColor];
pageControl.currentPageIndicatorTintColor = [UIColor blackColor];
pageControl.backgroundColor = [UIColor whiteColor];
UIStoryboard *storyBoard;
storyBoard = [UIStoryboard storyboardWithName:@"MainStoryboard.storyboard" bundle:nil];
UIViewController *walkthrough = [storyBoard instantiateViewControllerWithIdentifier:@"NextViewController"];
//[self presentViewController:walkthrough animated:YES completion:nil];
[self.window setRootViewController:walkthrough];
return YES;
}
Here is the completed code that works. Thanks very much for the help:
// User Defaults
UserDefaults *thisUserDefaults = [[UserDefaults alloc] init];
[thisUserDefaults registerDefaults];
if (![[[NSUserDefaults standardUserDefaults]
valueForKey:kAppHasRunBeforeKey] boolValue]) {
UIPageControl *pageControl = [UIPageControl appearance];
pageControl.pageIndicatorTintColor = [UIColor lightGrayColor];
pageControl.currentPageIndicatorTintColor = [UIColor blackColor];
pageControl.backgroundColor = [UIColor whiteColor];
UIStoryboard *storyBoard;
storyBoard = [UIStoryboard storyboardWithName:@"Main_iPhone" bundle:nil];
UIViewController *walkthrough =
[storyBoard instantiateViewControllerWithIdentifier:@"ViewController"];
[self.window setRootViewController:walkthrough];
[[NSUserDefaults standardUserDefaults] setBool:YES
forKey:kAppHasRunBeforeKey];
}
Upvotes: 3
Views: 2870
Reputation: 3506
The best and easiest possible method to show tips would be to use this library: https://github.com/chrismiles/CMPopTipView
Otherwise, if you want to do it with the approach you mentioned then you will need to keep a variable in NSUserDefaults
lets say a bool walkthroughShownOnce
. Initially if you are accessing the variable in the app delegate from NSUserDefaults like this:
bool tempInt = [[NSUserDefaults standardUserDefaults] boolForKey:@"walkthroughShownOnce"];
then it will return false
. This is when you show your walkthrough and in the end after you have shown the walk through, simply make the variable true like this:
[[NSUserDefaults standardUserDefaults] setBool:TRUE forKey:@"walkthroughShownOnce"];
Upvotes: 7