Skip to content

Instantly share code, notes, and snippets.

@Kursulla
Created June 5, 2013 10:10
Show Gist options
  • Save Kursulla/5712895 to your computer and use it in GitHub Desktop.
Save Kursulla/5712895 to your computer and use it in GitHub Desktop.
Local notifications! on iPhone
//In AppDelegate.m
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {
[self showAlarm:notification.alertBody];
application.applicationIconBadgeNumber = 0;
NSLog(@"AppDelegate didReceiveLocalNotification %@", notification.userInfo);
}
- (void)showAlarm:(NSString *)text {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"TVVodič alarm"
message:text delegate:nil
cancelButtonTitle:@"Hvala"
otherButtonTitles:nil];
[alertView show];
}
//On place you want to add notification:
[[UIApplication sharedApplication] cancelAllLocalNotifications];
UILocalNotification *localNotification = [[UILocalNotification alloc] init];
NSDate *dateToFire = [_show fullTime];
localNotification.fireDate = dateToFire;
localNotification.alertBody = [NSString stringWithFormat:@"Some text to show"];
localNotification.soundName = UILocalNotificationDefaultSoundName;
localNotification.applicationIconBadgeNumber = 1; // increment
NSDictionary *infoDict = [NSDictionary dictionaryWithObjectsAndKeys:@"Object 1", @"Key 1", @"Object 2", @"Key 2", nil];
localNotification.userInfo = infoDict;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment