本地通知从未出现。有人能告诉我为什么吗?
- (IBAction)addReminder:(id)sender {
self.datePicker.timeZone = [NSTimeZone timeZoneWithName: @"Asia/Tokyo"];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
NSString *formatedDate = [dateFormatter stringFromDate:self.datePicker.date];
NSLog(@"formatedDate>>>>>:%@", formatedDate);
NSDate *date = [dateFormatter dateFromString:formatedDate];
NSTimeZone *zone = [NSTimeZone systemTimeZone];
NSInteger interval = [zone secondsFromGMTForDate: date];
NSDate *localeDate = [date dateByAddingTimeInterval: interval];
NSLog(@"Setting a reminder for %@", localeDate);
UILocalNotification *localNotif = [[UILocalNotification alloc] init];
localNotif. fireDate = localeDate;
localNotif.soundName = UILocalNotificationDefaultSoundName;
localNotif.alertBody = @"ZEIT!";
localNotif.alertAction = @"Show me the Timer!";
localNotif.timeZone = zone;
localNotif.applicationIconBadgeNumber = [[UIApplication sharedApplication] applicationIconBadgeNumber] +1;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotif];
}结果:
formatedDate>>>>>:2015-08-09 23:32:00 Setting a reminder for 2015-08-09 23:32:00 +0000发布于 2015-08-10 22:37:34
确保您正在向用户请求显示通知的权限。
if ([UIApplication instancesRespondToSelector:@selector(registerUserNotificationSettings:)]){
[application registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert|UIUserNotificationTypeBadge|UIUserNotificationTypeSound categories:nil]];
}发布于 2015-08-12 21:23:59
致: kmcgrady,谢谢你的回答,但我试过了,它起作用了。
NSDate *now=[NSDate new];
localNotif.fireDate=[now dateByAddingTimeInterval:12];https://stackoverflow.com/questions/31920609
复制相似问题