dimanche 10 juillet 2016

Objective-C: UILocalNotification


ViewController: - (void)viewDidLoad { `[super viewDidLoad];` dateFormatter.dateFormat = @"dd/MM"; timeFormatter.dateFormat = @"HH:mm"; NSString *dateString = [dateFormatter stringFromDate:dateTime]; NSString *timeString = [timeFormatter stringFromDate:dateTime]; if ([dateString isEqual:@"23/06"]) { if ([timeString isEqual:@"23:30"]) { UILocalNotification *localNotification = [[UILocalNotification alloc] init]; localNotification.fireDate = dateTime; localNotification.alertBody = [NSString stringWithFormat:@"It's 11:30 PM 23th June!"]; localNotification.soundName = UILocalNotificationDefaultSoundName; localNotification.applicationIconBadgeNumber = 1; [[UIApplication sharedApplication] scheduleLocalNotification:localNotification]; } } } AppDelegate: [[UIApplication sharedApplication] scheduledLocalNotifications]; if ([UIApplication instancesRespondToSelector:@selector(registerUserNotificationSettings:)]){ [application registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert|UIUserNotificationTypeBadge| UIUserNotificationTypeSound categories:nil]]; } The notification isn't receiving when time equals string and date. Please help!

Aucun commentaire:

Enregistrer un commentaire