2013-03-06 2 views
1

나는 매우 간단해야하는 빠른 질문이 있습니다.iOS UILocalNotification - 배지 아이콘 및 알림 소리

첫째, 나는 게시 코드에 의해 시작 하겠어 :

-(void)notification 
{ 
UILocalNotification *localNotification = [[UILocalNotification alloc] init]; 

if (!localNotification) 
    return; 

// Current date 
NSCalendar *calendar = [NSCalendar currentCalendar]; // gets default calendar 
NSDateComponents *components = [calendar components:(NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit) fromDate:[NSDate date]]; // gets the year, month, day, hour and minutesfor today's date 
[components setHour:19]; 
[components setMinute:30]; 
[components setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"EST"]]; 

localNotification.fireDate = [calendar dateFromComponents:components]; 

localNotification.repeatInterval = NSDayCalendarUnit; 

[localNotification setAlertBody:@"Your 'Daily Quote' is ready!"]; 

[[UIApplication sharedApplication] scheduleLocalNotification:localNotification]; 

localNotification.applicationIconBadgeNumber = 1; 

localNotification.soundName = UILocalNotificationDefaultSoundName; 

}

localNotification가 표시되어 있는지 보이지만, 배지와 소리가 표시되지 및 재생 않습니다. 이것은 "repeatInterval"로 인해 루핑 되었기 때문일 수 있습니까?

어떻게 표시 할 수 있습니까? 알림은 지정된 시간에 표시되지만 배지 아이콘은 변경되지 않습니다.

감사합니다!

헨리

+1

설정 한 후에 알림을 예약합니다 소리와 badeg 아이콘, 그리고 전에하지. – Lefteris

+0

감사! @Lefteris! 간단한 질문, 빠른 응답, 만약 당신이 내가 upvote 및 동의 질문에 대답하고 싶습니다. –

+2

필요 없음. 다행히 도움이되었다 :-) – Lefteris

답변

3

당신은 당신의 코드 순서를 변경해야합니다 :

localNotification.applicationIconBadgeNumber = 1; 

localNotification.soundName = UILocalNotificationDefaultSoundName; 

전에 코드를 가지고 : 동일한 논리가 나를 위해 일이 아이폰 OS 5.1에있다

[[UIApplication sharedApplication] scheduleLocalNotification:localNotification]; 

을하지만, 코드를 주문. 통지가 시스템에 적용된 후에 badgeNumber 및 soundName을 재설정합니다. NotificationCenter는 객체 자체가 아닌 로컬 알림 객체에 포함 된 정보를 필요로하므로 알림 센터에서 soundName 또는 badgeNumber.Glad를 가져올 수 없습니다 .-