Reputation: 97
I have created a photography assignment generator app using dreamweaver/phonegap with some finishing touches in xcode. I have set up a settings bundle where the user can set a daily reminder on on off. it is preset to OFF, as i would rather not annoy people who don't want it. Because i have done this using dreamweaver, I can't find a way to access the settings bundle, so the user has to go to settings, flick the switch, and reboot the app to have it take effect.
What I would like to do is have the app ask them the first time the app is launched whether or not they would like to set up a daily reminder. If they tap yes, it should set the reminder setting to ON/YES, if no, it should continue on with the default set to no.
it would be even more awesome if I could have a "Maybe Later" button.
I am not great at programming, and it was a lot of work for me to get this working(thanks to help from the great folks on here and other sites on the net) I have tried using various IF/THEN, but I can't get it to work.
So here is what I have so far...would appreciate it greatly if any of you would be able to help me figure this out.
Thank you
Noel Chenier
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOtions:(NSDictionary *)launchOptions
{
[[UIApplication sharedApplication]
registerForRemoteNotificationTypes:
UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound];
NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
NSDictionary *appDefaults =[NSDictionary dictionaryWithObject:@"NO" forKey:@"enableNotifications"];
[defaults registerDefaults:appDefaults];
[defaults synchronize];
UILocalNotification *localNotif= [launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];
if (localNotif) {
NSLog(@"Recieved Notification %@",localNotif);
}
/*NSArray *keyArray = [launchOptions allKeys];
if ([launchOptions objectForKey:[keyArray objectAtIndex:0]]!=[nil)
{
NSURL *url = [launchOptions objectForKey:[keyArray objectAtIndex:0]];
self.invokeString = [url absoluteString];
}*/
return [super application:application didFinishLaunchingWithOptions:launchOptions];
}
Upvotes: 2
Views: 1167
Reputation: 8845
This is a pretty simple task, especially considering you're already using NSUserDefaults
. All you need to do is store a BOOL
in your defaults every time the app launches. For example:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOtions:(NSDictionary *)launchOptions {
NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
if(![defaults boolForKey:@"firstLaunch"]) {
//this key has never been set - this is the first launch
[defaults setBool:YES forKey:@"firstLaunch"];
//show your alert here that you only want to show on the
//first application launch
UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"Some Title"
message:@"Some message" delegate:self cancelButtonTitle:@"Cancel"
otherButtonTitles:@"Some Button", @"Another Button", @"One More Button",
nil];
[alert show];
}
}
Upvotes: 1