2013-05-07 56 views
1

我正在使用UILocalNotification,但它没有按时发射,而是在指定时间后8-10分钟通知我。下面是我使用UILocalNotification没有在正确的时间被触发

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的代码,我用这个。我做错了什么?

回答

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]; 
+0

这是工作的罚款。只需要用GeoFence测试:) – Hassy 2013-05-07 08:45:28

+0

主要问题是时区。评论它做了魔术 – Hassy 2013-05-07 08:59:24