UILocalNotification 失效

Alan S1 2015-08-13 08:44:37

- (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];
}

Result:

formatedDate>>>>>:2015-08-09 23:32:00 Setting a reminder for 2015-08-09 23:32:00 +0000
...全文
155 2 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
引用 1楼我是你的主体 的回复:
上面这段代码执行后提醒就是出现不了,但是用下面的代码就是能出来:

NSDate *now=[NSDate new]; 
localNotif.fireDate=[now dateByAddingTimeInterval:12]; 
Alan S1 2015-08-13
  • 打赏
  • 举报
回复
上面这段代码执行后提醒就是出现不了,但是用下面的代码就是能出来:

NSDate *now=[NSDate new]; 
localNotif.fireDate=[now dateByAddingTimeInterval:12]; 

29,049

社区成员

发帖
与我相关
我的任务
社区描述
主要讨论与iOS相关的软件和技术
社区管理员
  • iOS
  • 大熊猫侯佩
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧