UILocalNotificationから
iOS10以降のUNMutableNotificationContentにバージョンアップ作業をしているのですが、
指定の日付から毎日繰り返すにはどうすれば良いのでしょうか。
###コード
Objective
1// 初回再生時間 2日後の午前8時30分 2int day = 2; 3int hour = 8; 4int minute = 30; 5 6NSDate *nowDate = [NSDate date]; 7NSDateComponents *NowTimeComps = [Calendar components:(NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay | NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond) fromDate:nowDate]; 8 9int nowTime = (((int)NowTimeComps.hour * 60 ) + (int)NowTimeComps.minute) * 60 + (int)NowTimeComps.second; 10int setTime = day * 24 * 60 * 60; 11setTime += hour * 60 * 60; 12setTime += minute * 60; 13 14int setTimeDiff = setTime - nowTime; 15 16NSDate * alertDate = [[[NSDate alloc] initWithTimeInterval:setTimeDiff sinceDate:nowDate] autorelease];
Objective
1// UILocalNotification(iOS -9) 2// この処理の内容をバージョンアップさせる予定です。 3UILocalNotification *notification = [[UILocalNotification alloc] init]; 4notification.fireDate = alertDate; // <-通知させる日時を指定する 5notification.repeatInterval = NSCalendarUnitDay; // <-日付単位でリピートする 6notification.timeZone = [NSTimeZone localTimeZone]; 7notification.alertTitle = "タイトル"; 8notification.alertBody = "内容"; 9notification.soundName = UILocalNotificationDefaultSoundName; 10notification.alertAction = "OK"; 11 12[[UIApplication sharedApplication] scheduleLocalNotification:notification];
Objective
1// UNMutableNotificationContent(iOS 10-) 2// バージョンアップ用に処理を記述しましたが、指定日からリピート通知出来ません。 3UNMutableNotificationContent* content = [[UNMutableNotificationContent alloc] init]; 4content.title = [NSString localizedUserNotificationStringForKey:"タイトル" arguments:nil]; 5content.body = [NSString localizedUserNotificationStringForKey:"内容" arguments:nil]; 6content.sound = [UNNotificationSound defaultSound]; 7 8// 日付単位でリピートする 9NSUInteger units = NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond; 10NSDateComponents* triggerDate = [[NSCalendar currentCalendar] components:units fromDate:alertDate]; 11UNCalendarNotificationTrigger* trigger = [UNCalendarNotificationTrigger triggerWithDateMatchingComponents:triggerDate repeats:YES]; 12 13UNNotificationRequest* request = [UNNotificationRequest requestWithIdentifier:"notifer" content:content trigger:trigger];
###問題点
上記のUNMutableNotificationContentの処理で行うと
int day = 2;で指定した日数経過後に通知する事が出来ません。
その日(既に経過していれば翌日)の指定時間に通知され毎日リピートされます。
unitsにNSCalendarUnitDayを追加すると指定日時に通知させる事は出来ますが
リピート間隔が月単位になってしまいます。
修正方法やアイデアをお持ちの方がいれば、ご教授をお願い致します。
あなたの回答
tips
プレビュー