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

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.

Related

How can you detect if it is the first time a user opens an app [duplicate]

This question already has answers here:
How to get a "first time open"-view for my app?
(3 answers)
Closed 9 years ago.
Is it possible to detect if it is the first time a user opens an iOS application, using Objective-C?
I would like to show a welcome message when the user opens up the app for the first time, but not show it to them after that.
I'm looking for something like:
BOOL firstTime = [AppDelegate isFirstTimeOpeningApplication]
Look for some value in your app's preferences, or the existence of some file. If you don't find it, your app is running for the first time, so write the expected value to the preferences or create the file so that the next time your app runs you'll know that it's not the first time.
If you store the time and date of the first run instead of just a flag, you can determine how long it's been since the app was used. You might want your app to act like it's the first run if the user hasn't used your app in a very long time.
Note that this technique only works if the user hasn't deleted your app. When an app is deleted, all its data is removed. If you want to know if your app has ever run on that device before, even if it was deleted afterward, you'll need to record information to identify the device elsewhere, such as on your own server.
Use NSUserDefaults
//In applicationDidFinishLaunching:withOptions:
BOOL hasLaunchedBefore = [[NSUserDefaults standardUserDefaults] boolForKey:#"AppHasLaunchedBefore"];
if(!hasLaunchedBefore) {
//First launch
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:#"AppHasLaunchedBefore"];
}
else {
//Not first launch
}
Hope that helps!
You can save a "I've run before" flag in NSUserDefaults.
- (void)applicationDidFinishLaunching:(UIApplication *)application {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSString *firsttime = [defaults stringForKey:#"firsttime"];
if (firsttime == nil) {
TheOtherViewController *Other = [[TheOtherViewController alloc] initWithNibName:nil bundle:nil];
Other.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[window addSubview: Other.view];
[defaults setObject:#"lasttime" forKey:#"firsttime"];
} else { [window addSubview:viewController.view];
[window makeKeyAndVisible];
}
}
Use NSUserDefaults to store a flag which will indicate if the user has launched the app before or not. If the value of flag .. lets say "IsFirstTimeLaunched" is false then it means the user has not launched the app before.

Shows different view the 2nd time the app starts

I´m building an app for iphone.
I have two views. The first time the user starts the app, i wanna show the 1st view, he pushes a button and go´s to the 2nd view.
The 2nd time he starts the app, i want it to jump directly to the 2nd view.
Can you guys point me in the right direction?
I would use the NSUserDefaults for this
-(BOOL) shouldSkipFirstView
{
//boolForKey returns NO if that entry does not exist or is not associated with a bool
return [[NSUserDeafults standardUserDefaults] boolForKey:#"shouldSkipFirstView"];
}
-(void) skipFirstViewInFuture
{
[[NSUserDeafults standardUserDefaults] setBool:YES forKey:#"shouldSkipFirstView"];
[[NSUserDeafults standardUserDefaults] synchronize]; //optional line
}
-(UIViewController*) getStartupViewController
{
if([self shouldSkipFirstView])
{
[self skipFirstViewInFuture];
return [[[MySecondViewController alloc] init] autorelease];
}
else
{
return [[[MyFirstViewController alloc] init] autorelease];
}
}
You should look into NSUserDefaults. The concept will be to store a value as a preference the first time the app loads and show the 1st view. Then each time your app opens, check if that preference value is set and if so, display the 2nd view.
Create variable and save it to NSUserDefaults so first time when app is loaded set it to true and show view 1 and set it to false. Second time if it is false show view 2 and set it to true.
Code should be in app did finish launching in app delegate.
You just need some kind of record that the app has been opened. You could for example store an object in NSUserDefaults containing the version of the app, which is set on app did finish launching. You can then check to see if there is an object for that key at all, or if the recorded version is lower than the current version of the app (if you want to, for example, show it every time the version changes).

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.

Any way to show a view only once the app is used?

I am creating an app which requires the users to enter certain values when the app is used for the first time.
A settings screen with 4 UITextFields and a UIPicker.
This settings view can be accessed later using a button from the mainscreen.
Somebody please suggest some ideas
Thanks
Use the NSUserDefaults and set a BOOL or a NSDate to indicate that you app has been used for the first time.
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:#"firstUse"]

Remember Apps last screen in iPhone app

I want to remember the last screen of my app, means if I reopen my app, app should navigate me to the last screen where I were just before exiting app.
Thanks
Saurabh
Take a look at the NSUserDefaults API.
You could save an object for the current screen in the NSUserDefaults then check for that object on launch.
Create a NSMutableDictionary object when a view loads, and change it's value each time, and store it in the user defaults.
NSMutableDictionary *currentScreen = [[NSMutableDictionary alloc] init];
[currentScreen setObject:#"AboutPage" forKey:#"screen"];
NSUserDefaults *standardUserDefaults = [NSUserDefaults standardUserDefaults];
[standardUserDefaults setObject:currentScreen forKey:#"lastScreen"];
Then when the app loads, check the user defaults "lastScreen" key and load the appropriate view.
Hope this helps.
in iOS4 it's done automatically, because when you quit your application it's actually enters the background mode and doesn't quit. So when you "launch" it again, it opens at the same place the user left.
Previous versions of iOS don't have this feature and you should take care of it by yourself.
Depending on your application, you may want to think about using the Three20 library. This library has the sort of persistence you are looking for built in.