2012-12-10 3 views
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]; 

이 코드 부분을 여러 번 호출하여 여러 지역 알림을 예약하면 이상한 일이 발생할 수 있습니다.

  1. 알림 센터에 항목이 여러 개 있지만 배지 번호는 하나만 남습니다.
  2. 알림 중 하나를 클릭하면 다른 모든 알림이 사라집니다. 하지만 cancelAllLocalNotifications 메서드를 사용하지 않았습니다.

이 문제는 어떻게 해결할 수 있습니까?

+0

음, 무엇을 시도해 보셨습니까 ... –

+0

localNotif.applicationIconBadgeNumber = 1; 이 코드는 배지를 한 번 보여줍니다 (무엇을 생각합니까) ... –

+0

http://m.youtube.com/#/watch?v=ysm0QKs2a3Q&desktop_uri=%2Fwatch%3Fv%3Dysm0QKs2a3Q이 링크를 확인하십시오 .. –

답변

8

앱이 백그라운드에있는 동안 로컬 알림으로 배지 번호를 동적으로 업데이트 할 수 없습니다. 푸시 알림을 사용해야합니다.

+1

속성 applicationIconBadgeNumber에 대한 설명이 올바르지 않습니다. 문서의 설명에 나와 있듯이이 속성에 따라 배지 번호를 업데이트해야하며 사용 된 알림과 관련이 없습니다. 클릭. – seanxiaoxiao