I would like some help to review my code. My intention is to display a view with T&C when the app is first opened.
I am currently using the following code under the FirstViewController, as suggested here:
- (void)viewDidLoad: (BOOL)animated
{
[super viewDidLoad];
NSUserDefaults * standardUserDefaults = [NSUserDefaults standardUserDefaults];
BOOL isAccepted = [standardUserDefaults boolForKey:@"iHaveAcceptedTheTerms"];
if (!isAccepted) {
[self presentViewController:@"Terms" animated:YES completion:nil];
} else {
[self.navigationController pushViewController:@"First" animated:YES];
}
The reason why I used @"Terms"
and @"First"
is because otherwise it gives me error and also because I saw it suggested on a Youtube video, I am wrong?
The other method I also tryed was the one suggested on the Youtube Video:
- (void)viewDidLoad: (BOOL)animated
{
[super viewDidLoad];
if ([[NSUserDefaults standardUserDefaults] boolForKey:@"FirstLaunch"])
{}
else {
// Place code here
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main_iPhone" bundle:nil];
UIViewController *vc = [mainStoryboard instantiateViewControllerWithIdentifier:@"Terms"];
[vc setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"FirstLaunch"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
But neither work. Can you kindly share your thoughts and help me?
Thanks :)