Loading ModalView only on first open - iphone

I've created a modal view that loads on top of my tabBar to serve as a 3 step welcome screen.
While all of that works OK, the problem I'm having is finding a way to load it only once, so that the user doesn't have to deal with a welcome message on every single load.
I've done some research, and it looks like I might be able to call a method with NSTimer, but I'm not sure if that's a proper way to do it.

In your app delegate, set Bool and save in NSUserDefault Check if BOOL is set. If not then present view modally also set the BOOL.
Code might look like this:
In your appdelegate implementatuin. Application didFinishLaunching method:
if (![[NSUserDefaults standardUserDefaults] boolForKey:#"FirstTimeBool"])
{
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:#"FirstTimeBool"];
// present view controller modally after this
}

You can store this information in NSUserDefaults that exactly what's it is for :
At first start :
[[NSUserDefaults standardUserDefaults] setValue:[NSNumber numberWithBool:YES] forKey:#"IS_FIRST_LAUNCH"];
Then to know if it is the first time you run the app :
BOOL isFirstLaunch = [[[NSUserDefaults standardUserDefaults] valueForKey:#"IS_FIRST_LAUNCH"] boolValue]
Hope this helps,
Vincent

Related

Keep track of launches bug

I found some threads that discuss this and implemented it into my code, however I'm having an error.
I am trying to do something every 5th launch.
Also the code sets launchAmounts, is that built in into userDefaults, or do I have to declare this somewhere?
I am doing this from viewwillappear in my main view controller.
NSUserDefaults * userDefaults = [NSUserDefaults standardUserDefaults];
NSInteger appLaunchAmounts = [userDefaults integerForKey:#"LaunchAmounts"];
appLaunchAmounts = appLaunchAmounts %5;
NSLog(#"app has been launched = %d", appLaunchAmounts);
[userDefaults setInteger:appLaunchAmounts+1 forKey:#"LaunchAmounts"];
if (appLaunchAmounts==0) {
That code looks like it should work, except for the fact that you have it in viewWillAppear. That method could be called many times in one run if you're switching back and forth between different view controllers. You should put it in the applicationDidFinishLaunching method in the app delegate.
What's not working the way you have it now?

How to make scollView (for T&C) only show up once at begin of app, then never show up again?

My questions is...how to make....this...
I am trying to make a scollview to show the term&condition at beginning of my app when the user is 1st time using the app.
if the user accepted the T&C (by clicking accept button), this T&C scollview will never show up again at beginning of the app, as he already accepted. So he will be free to use the app in future.
How do I implement this? any suggestions?
Use NSUserDefaults with a key like "TCShown". If the key does not exist in the NSUserDefaults at the beginning of the launch, you show the T&C and create "TCShown" value, set it to YES ([NSNumber numberWithBool:YES];) and store it to the NSUserDefaults.
Edit:
Assuming that you want to present the T&C in your first viewController,
#define kTCViewedFlag = #"tcViewed"
-(void) viewDidAppear {
NSUserDefaults *myDefaults = [NSUserDefaults standardUserDefaults];
if(![myDefaults objectForKey:kTCViewedFlag]) {
//show the TC
}
}
-(IBAction) userAcceptedTC {
[[NSUserDefaults standardUserDefaults] setObject:[NSNumber numberWithBool:YES] forKey:kTCViewedFlag];
[[NSUserDefaults standardUserDefaults] synchronize];
//dismiss the scrollView
}
-(IBAction) userDidDeclineTC {
//handle refusal of TC
}
In addition to Kaan's answer, you can add the TCShown field to the server and update the values accordingly. This will take care of the case when the user who has already accepted the T&C's logs in from a different device.
Maybe you'll find this useful: RLAgreement View Controller
This project allows developers to include
and Agreement, Terms of Service, Non Disclosure Agreement, etc. to an
iPhone App. The controller stores a variable in the user's settings
when the user has a valid agreement and it checks every time the user
opens the App.

How to implement instruction view for iPhone app

I have 2 pages that I want to show as instructions the first time the app is run. How would I accomplish this?
You can utilize NSUserDefaults for something like this.
if(![[NSUserDefaults standardUserDefaults] boolForKey:#"didLoad"]) {
//Show your instructions
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:#"didLoad"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
What this does is, check if the didLoad bool is FALSE (Which will be on first Load), if it is you show your instructions and set the BOOL to YES for the next Launch. You can put this in your viewDidLoad method.

Registration form on an iphone application

I have an application developed using iOS5. I have used the storyboard to design the whole screens. The problem I am facing right now is that, when the user runs the application for the very first time, I have to show a view for the user to register. I have no clue on earth on how to do it. I have created the registration forms on the storyboard itself.
Can someone put some light on this issue please?
Thankx in advance.
Try this (and also check this):
Set a value after the user starts the application:
[[NSUserDefaults standardUserDefaults] setValue:[NSNumber numberWithInt:1] forKey:#"registered"];
[[NSUserDefaults standardUserDefaults] synchronize];
and then check with this:
NSNumber *numb=[[NSUserDefaults standardUserDefaults] objectForKey:#"registered"];
if ([numb isEqualToNumber:[NSNumber numberWithInt:1]]) {
NSLog(#"registered");
}else{
NSLog(#"not registered");
}

How to make a favourite list iphone

I am making an app that has two tabs, one of which is a "favourite" tab. In the other tab called "search", I have a list of results displayed in a table view, when you tap one, you get to see the detail of that particular result. What I'm trying to do here is, there is a button in the detail view, when it is pressed, the current result gets sent to the "favourite" tab. I tried to use delegate to pass the information, but it didn't work out. Here is my code:
DetailViewController.m
-(IBAction) addSomething {
[self.delegate detailViewController:self addToFavourite:self.something];
}
FavouriteViewController.m, implement the delegate method:
- (void) detailViewController:(DetailViewController *)detailViewController addToFavourite:(Something *)something{
detailViewController.delegate = self;
[thingsList addObject:something];
[theTableView reloadData];
}
Everything is built and fine, but when I click "add" button in the detail view, the data doesn't get sent to "favourite" tab's view. Can anyone help me with this one? Do I need to use core data in this case, I never used core data before. Thanks.
One way to do it that is drop dead easy is storing your information in NSUserDefaults.
NSUserDefaults *defaults = [NSUserDefaults standardDefaults];
[defaults setObject:thingsList forKey:#"myData"];
[defaults synchronize];
When you load your data up in your other tab, just fill it from user defaults.
NSUserDefaults *defaults = [NSUserDefaults standardDefaults];
otherData = [defaults objectForKey:#"myData"];
I probably abuse user defaults more than I should, but it makes for a very easy way to store your data locally and have it persist between runs. It will also backup with iTunes for added persistence. Hope this helps.