の終了日を設定することは可能UILocalNotification
ですか?
通知を毎日 ( ) 送信したいのですNSDayCalendarUnit
が、終了日 (期限) を超えることはできません。たとえば、成長中の口ひげの写真を 1 年間毎日撮影していて、1 年後に通知が表示されません。
あなたが私の見解を理解してくれることを願っています...
の終了日を設定することは可能UILocalNotification
ですか?
通知を毎日 ( ) 送信したいのですNSDayCalendarUnit
が、終了日 (期限) を超えることはできません。たとえば、成長中の口ひげの写真を 1 年間毎日撮影していて、1 年後に通知が表示されません。
あなたが私の見解を理解してくれることを願っています...
UILocalNotification
ドキュメントで読むことができるようなオプションはありません。
あなたの唯一のオプションは、すべてのユーザーがアプリを起動したときに年が終わったかどうかを確認することです.
UILocalNotification
オブジェクトでは、プロパティを設定し、終了日をディクショナリに入れて、後でクエリを実行して通知の有効期限が切れているかどうかを判断することをお勧めしrepeatInterval
ますuserInfo
。例えば:
UILocalNotification* uiLocalNotification;
uiLocalNotification = [[UILocalNotification alloc] init];
//Set the repeat interval
uiLocalNotification.repeatInterval = NSCalendarUnitDay;
NSDate* fireDate = ...
//Set the fire date
uiLocalNotification.fireDate = fireDate;
//Set the end date
NSDate* endDate = ...
uiLocalNotification.userInfo = @{
@"endDate": endDate
};
UIApplication* application = [UIApplication sharedApplication];
[application scheduleLocalNotification:uiLocalNotification];
//...
//Somewhere else in your codebase, query for the expiration and cancel, if necessary
UIApplication* application = [UIApplication sharedApplication];
NSArray* scheduledNotifications = application.scheduledLocalNotifications;
NSDate* today = [NSDate date];
for (UILocalNotification* notification in scheduledNotifications) {
NSDate* endDate = notification.userInfo[@"endDate"];
if ([today earlierDate:endDate] == endDate) {
//Cancel the notification
[application cancelLocalNotification:notification];
}
}
Use following code:
UILocalNotification *localNotification = [[UILocalNotification alloc] init];
localNotification.repeatInterval = NSDayCalendarUnit;