gpt4 book ai didi

ios - iOS UILocalNotification-角标(Badge)图标和通知声音

转载 作者:行者123 更新时间:2023-12-01 19:12:52 26 4
gpt4 key购买 nike

我有一个简短的问题,应该很简单。

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

-(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”在循环吗?

如何显示这些内容?通知在指定时间显示,但徽章图标未更改...

谢谢!

-亨利

最佳答案

您应该更改代码顺序:

localNotification.applicationIconBadgeNumber = 1;

localNotification.soundName = UILocalNotificationDefaultSoundName;

之前的代码:
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];

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

关于ios - iOS UILocalNotification-角标(Badge)图标和通知声音,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15236848/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com