【发布时间】:2017-04-24 11:30:41
【问题描述】:
我正在尝试在我的应用中触发本地通知,并且我正在使用以下代码 -
-(void)applicationDidEnterBackground:(UIApplication *)application {
NSDate *alarmTime=[[NSDate date] dateByAddingTimeInterval:5.0];
UIApplication *app=[UIApplication sharedApplication];
UILocalNotification *notifiArea=[[UILocalNotification alloc] init];
if (notifiArea) {
notifiArea.fireDate=alarmTime;
notifiArea.timeZone=[NSTimeZone defaultTimeZone];
notifiArea.repeatInterval=0;
notifiArea.soundName=@"";
notifiArea.alertBody=@"This is a push notification";
[app scheduleLocalNotification:notifiArea];
}
}
- (void)applicationWillEnterForeground:(UIApplication *)application {
UIApplication *app=[UIApplication sharedApplication];
NSArray *oldNotifications=[app scheduledLocalNotifications];
if([oldNotifications count]>0){
[app cancelAllLocalNotifications];
}
}
现在当我调试应用程序时,我的闹钟时间即将到来 2017-04-24 11:27:51 +0000,但我的模拟器时间是 4:55pm。
有什么问题?
【问题讨论】:
-
你签入ios 9了吗?
-
scheduleLocalNotification 在 ios 10 中已弃用。
-
由于时区的原因,您得到的时间不同
-
您的代码在我的设备上运行。我可以收到通知
-
大部分问题可能与时区有关。使用 systemTimeZone 并检查。如果您不知道时区。检查此链接stackoverflow.com/questions/18424569/…
标签: ios objective-c uilocalnotification