2013-05-07 54 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