지금 응용 프로그램에서 로컬 알림을 사용하고 있지만 이상한 점을 발견했습니다.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이 링크를 확인하십시오 .. –