Created
June 5, 2013 10:10
-
-
Save Kursulla/5712895 to your computer and use it in GitHub Desktop.
Local notifications! on iPhone
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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