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

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"]

Related

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.

Alternative to InAppSettingsKit

Is there an alternative to InAppSettingsKit that is simpler? I find myself needing only 20% of what it offers.
How about ESCOZ's QuickDialog library? Seems like a reasonable alternative.
Well, one alternative is to just build your own settings panel with a regular UIViewController and some buttons and switches, etc. and then save the settings using NSUserDefaults, e.g.
- (IBAction)mySettingSwitchAction:(UISwitch *)theSwitch
{
//save the switch setting
[[NSUserDefaults standardUserDefaults] setBool:theSwitch.on forKey:#"myPreferenceName"];
}
then you can load it again anywhere in your app using
BOOL theValueISet = [[NSUserDefaults standardUserDefaults] boolForKey:#"myPreferenceName"];
Values you set in NSUserDefaults are persistent so if the app is closed and opened again they retain their values. You can call synchronize on NSUserDefaults to force it to save/load the values but this happens automatically on app open/close anyway.

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 read settings from NSUserDefaults when using inappsettingskit

I am new to XCode and iOS programming. So please assume nothing ...
I am trying to incorporate the inappsettings bundle into my project. It is the 3rd party product found at http://inappsettingskit.com/
I have included all (I think) the files from the kit as well as their settings.app bundle. Through IB, I have built a tab bar where each tab item is a navigational controller. The view of my "Settings" tab is a view controller of class IASKAppSettingsViewController.
When I run my app, the default setting screen included in the kit displays and everything seems to run correctly.
However, I cannot figure out how to actually use the settings that I select in my app. I believe that the settings are stored in [NSUserDefaults standardUserDefaults], but when I query this as below, NSString* s always comes back as nil.
NSUserDefaults* d = [NSUserDefaults standardUserDefaults];
NSString* s = [d objectForKey:#"ROOKIE"];
I have also tried initializing [[NSUserDefaults standardUserDefaults] as follows:
[[NSUserDefaults standardUserDefaults] registerDefaults:[NSDictionary dictionaryWithContentsOfFile:[[NSBundle mainBundle] pathForResource:#"Root~iphone.InApp" ofType:#"plist"]]];
I have added the key "ROOKIE" to the Root~iphone.InApp.plist file included in the Settings bundles. I put "ROOKIE" in the "key" column and some string value in the "value" column.
Maybe here is where I am doing something wrong? I don't really understand how the .plist files work and if I am accessing the correct one, or if I am doing it in the right way. I have played around and I can't seem to extract any value from any .plist file so it would seem it's my approach rather than the file?
Any insight would be appreciated.

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.