UILocalNotification 失效

Alan S1 2015-08-12 08:54:05
- (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 提醒就是出现不了,但是用下面的代码就是能出来: NSDate *now=[NSDate new]; localNotif.fireDate=[now dateByAddingTimeInterval:12]; –
...全文
129 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
Alan S1 2015-08-12
  • 打赏
  • 举报
回复
- (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];
}
Alan S1 2015-08-12
  • 打赏
  • 举报
回复
- (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];
}
谁能告诉我这段代码为啥不出来提醒呢?
Alan S1 2015-08-12
  • 打赏
  • 举报
回复
提醒就是出现不了,但是用下面的代码就是能出来:
NSDate *now=[NSDate new]; 
localNotif.fireDate=[now dateByAddingTimeInterval:12];

29,027

社区成员

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

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