我正在使用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];
我在CLLocationManager
的 didEnterRegion 委托中使用此功能。我做错了什么?
答案 0 :(得分:3)
这是工作代码:
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];