iOS 5的“通知中心”API是什么?

6

NSNotificationCenter 是完全无关的东西。 - user529758
UILocalNotification会在我的应用名称旁边放置一个带有“1”的红色框,但不会标记横幅... - Ryan Copley
2个回答

5

数字徽章不是本地通知的唯一属性。它还可以显示横幅,并播放声音。这些横幅随后会添加到通知中心。

以下是一个示例:

- (void)addNotification {
    UILocalNotification *localNotification = [[UILocalNotification alloc] init];
 
    localNotification.fireDate = self.datePicker.date;
    localNotification.alertBody = self.messageField.text;
    localNotification.soundName = UILocalNotificationDefaultSoundName;
    localNotification.applicationIconBadgeNumber = 1;
 
    NSDictionary *infoDict = [NSDictionary dictionaryWithObjectsAndKeys:@"Object 1", @"Key 1", @"Object 2", @"Key 2", nil];
    localNotification.userInfo = infoDict;
 
    [[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
    [localNotification release];
}

以下是一个教程:http://www.icodeblog.com/2010/07/29/iphone-programming-tutorial-local-notifications/


该教程介绍了如何在iPhone上实现本地通知。

2

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接