2
我現在在應用程序中使用本地通知,但是我發現有些奇怪。關於iOS上本地通知的問題
我設置並安排了這樣的通知。
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];
這部分代碼可以調用多次來安排幾個本地通知,現在奇怪的事情來了。
- 雖然通知中心中有多個條目,但徽章號仍然是一個。
- 一旦我點擊其中一個通知,所有其他通知就會消失。但我沒有使用cancelAllLocalNotifications方法。
我該如何解決這個問題,謝謝。
那麼你有什麼嘗試... –
localNotif.applicationIconBadgeNumber = 1;此代碼顯示徽章一次(您認爲是什麼)... –
http://m.youtube.com/#/watch?v=ysm0QKs2a3Q&desktop_uri=%2Fwatch%3Fv%3Dysm0QKs2a3Q查看此鏈接.. –