1

の終了日を設定することは可能UILocalNotificationですか?

通知を毎日 ( ) 送信したいのですNSDayCalendarUnitが、終了日 (期限) を超えることはできません。たとえば、成長中の口ひげの写真を 1 年間毎日撮影していて、1 年後に通知が表示されません。

あなたが私の見解を理解してくれることを願っています...

4

3 に答える 3

4

UILocalNotificationドキュメントで読むことができるようなオプションはありません。

あなたの唯一のオプションは、すべてのユーザーがアプリを起動したときに年が終わったかどうかを確認することです.

于 2013-08-06T10:38:17.767 に答える
1

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];
    }
}
于 2015-06-26T22:00:31.970 に答える
-3
Use following code:

UILocalNotification *localNotification = [[UILocalNotification alloc] init];
localNotification.repeatInterval = NSDayCalendarUnit;
于 2013-08-06T10:40:19.637 に答える