【发布时间】:2012-12-10 02:30:16
【问题描述】:
我现在在应用程序中使用本地通知,但我发现有些奇怪。
我设置和安排这样的通知。
UILocalNotification *localNotif = [[UILocalNotification alloc] init];
if (localNotif == nil) {
return;
}
NSDate *now = [[NSDate alloc] init];
now = [now dateByAddingTimeInterval:dayToFinish * 24 * 60 * 60];
NSDateComponents *components = [[NSCalendar currentCalendar] components:NSHourCalendarUnit fromDate:now];
components = [[NSCalendar currentCalendar] components:NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit fromDate:now];
int month = [components month];
int day = [components day];
int year = [components year];
NSCalendar *calendar = [NSCalendar autoupdatingCurrentCalendar];
NSDateComponents *dateComps = [[NSDateComponents alloc] init];
[dateComps setYear:year];
[dateComps setMonth:month];
[dateComps setDay:day];
[dateComps setHour:18];
[dateComps setMinute:15];
[dateComps setSecond:0];
//There are a lot to set up the fire date, you could ignore it.
NSDate *fireDate = [calendar dateFromComponents:dateComps];
localNotif.fireDate = fireDate;
localNotif.timeZone = [NSTimeZone defaultTimeZone];
localNotif.alertBody = [NSString stringWithFormat:@"Test message %@", self.name];
localNotif.applicationIconBadgeNumber = 1;
NSDictionary *infoDict = [NSDictionary dictionaryWithObject:self.name forKey:@"ListRecordName"];
localNotif.userInfo = infoDict;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotif];
这部分代码可以多次调用来安排多个本地通知,现在奇怪的事情来了。
- 尽管通知中心有多个条目,但徽章编号仍为 1。
- 单击其中一个通知后,所有其他通知都会消失。但是我没有使用 cancelAllLocalNotifications 方法。
如何解决这个问题,谢谢。
【问题讨论】:
-
那么你尝试了什么...
-
localNotif.applicationIconBadgeNumber = 1;此代码仅显示一次徽章(您认为如何)...
-
m.youtube.com/#/… 看看这个链接..
-
@Programmer... 我不认为 applicationBadgeNumber = 1 导致问题。正如文档所说“默认值为 0,这意味着“没有变化”。应用程序应使用此属性的值来增加当前图标徽章编号(如果有)。”如果有多个此类通知实例。徽章编号应等于通知实例的数量。
标签: objective-c ios uilocalnotification