Вот код, который я использовал в моем приложении для создания локального уведомления:UILocalNotification не работает в моем устройстве
UILocalNotification *aNotification = [[UILocalNotification alloc] init];
if (aNotification == nil)
{
NSLog(@"localNotif");
return;
}
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
NSTimeZone *sourceTimeZone = [NSTimeZone timeZoneForSecondsFromGMT:19800];
[dateFormatter setTimeZone:sourceTimeZone];
NSDate *sourceDate = [dateFormatter dateFromString:@"2013-02-16 15:00:00"];
NSTimeZone* destinationTimeZone = [NSTimeZone systemTimeZone];
NSInteger destinationGMTOffset = [destinationTimeZone secondsFromGMTForDate:sourceDate];
NSTimeInterval interval = destinationGMTOffset;
NSDate* destinationDate = [[NSDate alloc] initWithTimeInterval:interval sinceDate:sourceDate];
aNotification.fireDate = destinationDate;
aNotification.timeZone = [NSTimeZone defaultTimeZone];
NSLog(@"destinationDate %@",destinationDate);
aNotification.alertBody = @"About To Start";
aNotification.alertAction = @"View";
[[UIApplication sharedApplication] scheduleLocalNotification:aNotification];
[dateFormatter release];
[destinationDate release];
[aNotification release];
Но когда я проверить его в устройстве путем изменения даты и времени из приложения Настройки, событие не стреляет. Что я делаю не так?
При печати destinationDate
в консоли он приходит так:
destinationDate 2013-02-16 15:00:00 +0000
да. Верно. – Dee
, в какое время вы устанавливаете ... make NSLog в appdelegate, получите код уведомления. – Rajneesh071
Я не получаю уведомление только для его печати в NSLog. – Dee