我在iPhone應用程序開發方面有點新。所以如果這是一個蹩腳的問題,我首先抱歉。現在我的問題是。在我的應用程序用戶有時鐘撥號,他將選擇小時和分鐘。使用該小時和分鐘,我想根據報警系統設置用戶報警後,它會爲本地通知設置,我的本地通知工作只有鬧鐘時間顯示wrong.So到目前爲止,我有做過這樣的我在iOS中收到錯誤的通知時間?
NSCalendar *calendar = [NSCalendar autoupdatingCurrentCalendar];
calendar.timeZone = [NSTimeZone defaultTimeZone];
calendar.locale = [[NSLocale alloc]initWithLocaleIdentifier:@"en_US_POSIX"];
NSDateComponents *currentTimeComponents = [calendar components:NSCalendarUnitYear|NSCalendarUnitMonth|NSCalendarUnitDay|NSCalendarUnitHour|NSCalendarUnitMinute fromDate:[NSDate date]];
currentTimeComponents.hour = [_hourlLabel.text intValue];
currentTimeComponents.minute = [_minuteLabel.text intValue];
currentTimeComponents.second = 00;
NSDate *date = [calendar dateFromComponents:currentTimeComponents];
NSLog(@"User set date: %@",date);
UILocalNotification *localNotification = [[UILocalNotification alloc] init];
localNotification.repeatInterval = NSCalendarUnitDay;
localNotification.timeZone = [NSTimeZone defaultTimeZone];
// Schedule the notification
localNotification.fireDate = date;
localNotification.alertBody = @"It has notification from xxxx";
localNotification.alertAction = @"Show me the item";
localNotification.applicationIconBadgeNumber = [[UIApplication sharedApplication] applicationIconBadgeNumber] + 1;
localNotification.soundName = @"clockalarmfrog.mp3";
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
NSLog(@"User setup local notifications: %@",localNotification);
NSTimeInterval secs = [localNotification.fireDate timeIntervalSinceDate:[NSDate date]];
NSLog(@"animation time duration in NSTimeInterval: %f",secs);
現在假設用戶已經爲下一個鬧鐘時間設置了5:51 PM,當前時間是5:20 PM.Now使用我的代碼我得到了這個。
2015-05-29 17:20:11.626 xxxx[651:12248] 17:20:11 PM
2015-05-29 17:21:05.988 xxxx[651:12248] User set date: 2015-05-28 23:51:00 +0000
2015-05-29 17:21:06.099 xxxx[651:12248] User setup local notifications: <UIConcreteLocalNotification: 0x7fd9a8c7de60>{fire date = Friday, May 29, 2015 at 5:51:00 AM Bangladesh Standard Time, time zone = Asia/Dhaka (GMT+6) offset 21600, repeat interval = NSCalendarUnitDay, repeat count = UILocalNotificationInfiniteRepeatCount, next fire date = Saturday, May 30, 2015 at 5:51:00 AM Bangladesh Standard Time, user info = (null)}
2015-05-29 17:21:06.099 xxxx[651:12248] animation time duration in NSTimeInterval: -41406.099645
2015-05-29 17:21:06.099 xxxx[651:12248] animation reverse time duration in NSTimeInterval: 44993.900355
2015-05-29 17:21:06.168 xxxx[651:12248] duration: 44993.900355
我也試過。 (它不工作,其實AM/PM上的問題是設定PM/AM,但它總是計算AM。 – Emon