29,027
社区成员
发帖
与我相关
我的任务
分享
- (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];
}
- (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];
}
谁能告诉我这段代码为啥不出来提醒呢?NSDate *now=[NSDate new];
localNotif.fireDate=[now dateByAddingTimeInterval:12];