I implemented a local notification in my game app that fires up once a day for a daily bonus. It all works fine when I tap the notification banner, however, when i get in to the app from the app icon, the local notification doesn't work like it should.
Here is my code:
-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions{
.......
.......
application.applicationIconBadgeNumber = 0;
UILocalNotification *localNotif = [launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];
if (localNotif)
{
NSLog(@"recieved notification %@",localNotif);
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Daily Bonus"
message:@"You recieved 100 free coins"
delegate:nil
cancelButtonTitle:nil
otherButtonTitles:@"ok", nil];
[alert show];
[alert release];
NSUserDefaults *standardUserDefaults = [NSUserDefaults standardUserDefaults];
float balance = [standardUserDefaults floatForKey:kCurrentScore];
balance +=100.0f;
NSLog(@"%g",balance);
[standardUserDefaults setFloat:balance forKey:kCurrentScore];
[standardUserDefaults synchronize];
}
I would appreciate any help.