gpt4 book ai didi

iphone - UILocalNotification 每分钟重复一次

转载 作者:行者123 更新时间:2023-11-28 22:44:50 25 4
gpt4 key购买 nike

我想每分钟发送一次本地通知,这是我正在使用的代码:

[[UIApplication sharedApplication] cancelAllLocalNotifications];

UILocalNotification *notif = [[UILocalNotification alloc] init];

if (notif == nil) {
return;
}

notif.timeZone = [NSTimeZone defaultTimeZone];

notif.alertBody = @"Test notification!";
notif.alertAction = @"View";
notif.soundName = UILocalNotificationDefaultSoundName;
notif.applicationIconBadgeNumber += 1;

notif.repeatInterval = NSMinuteCalendarUnit;

[[UIApplication sharedApplication] scheduleLocalNotification:notif];

通知只开始一次,永远不会重复。我哪里弄错了?

最佳答案

您必须为您的通知设置一个fireDate,否则它不会重复而是立即触发。

The fire date is interpreted according to the value specified for timeZone. If the specified value is nil or is a date in the past, the notification is delivered immediately.

关于iphone - UILocalNotification 每分钟重复一次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13490573/

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