gpt4 book ai didi

ios - UILocalNotification 没有在正确的时间触发

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

我正在使用 UILocalNotification但它没有按时触发,而是在指定时间后 8-10 分钟通知我。这是我正在使用的代码

    UILocalNotification *localNotif = [[UILocalNotification alloc] init];
if (localNotif == nil)
return;

NSDateFormatter *dateFormat = [[NSDateFormatter alloc]init];
[dateFormat setDateFormat:@"YYYY-MM-dd HH:mm:ss"];
NSString *dateString = [dateFormat stringFromDate:[NSDate date]];
NSDate *notificationDate = [dateFormat dateFromString:dateString];
localNotif.fireDate = notificationDate;
localNotif.timeZone = [NSTimeZone timeZoneWithAbbreviation:@"GMT"];

// Notification details
localNotif.alertBody = @"Appear";
// Set the action button
localNotif.alertAction = @"Action";

localNotif.soundName = UILocalNotificationDefaultSoundName;

// Schedule the notification
[[UIApplication sharedApplication] scheduleLocalNotification:localNotif];

我在 中使用它didEnterRegion CLLocationManager 的代表.我做错了什么?

最佳答案

这是工作代码:

UILocalNotification* n1 = [[UILocalNotification alloc] init];
n1.fireDate = [NSDate dateWithTimeIntervalSinceNow: 60];
n1.alertBody = @"one";
UILocalNotification* n2 = [[UILocalNotification alloc] init];
n2.fireDate = [NSDate dateWithTimeIntervalSinceNow: 90];
n2.alertBody = @"two";
[[UIApplication sharedApplication] scheduleLocalNotification: n1];
[[UIApplication sharedApplication] scheduleLocalNotification: n2];

关于ios - UILocalNotification 没有在正确的时间触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16414511/

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