1
這裏是我在我的應用程序已經用於生成本地通知代碼: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 2013-02-15 10:59:04
你什麼時候設置...使NSLog進入appdelegate,接收通知代碼.. – Rajneesh071 2013-02-15 11:02:56
我沒有收到通知,只能在NSLog中打印它。 – Dee 2013-02-15 11:03:53