在背景中显示app时的通知

时间:2016-01-08 21:37:06

标签: ios swift uilocalnotification

当应用在后台时,我需要显示某些本地通知。没有NSNotificationCenter的帮助,我怎么能这样做?

1 个答案:

答案 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];