1

我正在使用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。我做错了什么?

4

1 回答 1

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];
于 2013-05-07T08:30:20.403 回答