【问题标题】:iOS UILocalNotification - Badge Icon and Notification SoundiOS UILocalNotification - 徽章图标和通知声音
【发布时间】:2013-02-20 14:58:53
【问题描述】:

我有一个简单的问题。

首先,我将通过发布代码开始:

-(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”导致循环?

我怎样才能显示这些?通知正在指定时间显示,但徽章图标未更改...

谢谢!

-亨利

【问题讨论】:

  • 在设置声音和标记图标之后而不是之前安排通知。
  • 谢谢! @Lefteris!简单的问题,快速的回复,如果您想回答我会支持并接受的问题。
  • 不需要。很高兴有帮助:-)

标签: ios notifications uilocalnotification badge


【解决方案1】:

你应该改变你的代码顺序:

localNotification.applicationIconBadgeNumber = 1;

localNotification.soundName = UILocalNotificationDefaultSoundName;

取之前的代码:

[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];

相同的逻辑在 iOS 5.1 对我来说是有效的,但代码顺序不同。 在通知应用到系统后,您重置了 badgeNumber 和 soundName。 NotificationCenter 需要本地通知对象包含的信息,而不是对象本身,因此,在那个时候,NotificationCenter 无法获取 soundName 或 badgeNumber。很高兴有帮助:-)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-01-05
    • 1970-01-01
    • 2014-08-09
    • 1970-01-01
    • 1970-01-01
    • 2016-01-14
    • 1970-01-01
    相关资源
    最近更新 更多