当应用在后台时,我需要显示某些本地通知。没有NSNotificationCenter的帮助,我怎么能这样做?
答案 0 :(得分:0)
Andrey Chernukha在第一次评论中是对的。 以下是实现简单本地通知的代码:
UILocalNotification *localNotification = [[UILocalNotification alloc] init];
localNotification.repeatInterval = 0;
NSDate *now = [NSDate date];
NSDate *dateToFire = [now dateByAddingTimeInterval:10];
localNotification.fireDate = dateToFire;
localNotification.alertBody = @"Test local notification";
localNotification.soundName = UILocalNotificationDefaultSoundName;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];