1

私は大きな問題を抱えています!私の問題は、デリゲートに localnotification コードを実装したことです。このコードを didEnterBackround メソッドに入れました。ただし、didEnterBackround ごとに localnotifi を取得します。最新の通知がなくなった場合、新しい通知の発火日のみが開始される可能性のある方法はありますか? 5 日後に発火する localnotifi がある場合のように。アプリを 5 回開いて閉じて 5 日間待つと、5 つのローカル通知が届きます。アプリに発火日を 1 つだけ作成させ、これが表示された後に新しい発火日を開始することは可能ですか?!

私のコード:

NSCalendar  *calender = [NSCalendar autoupdatingCurrentCalendar];
NSDate *currentDate = [NSDate date];

NSDateComponents *dateComponents = [calender components:(NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit) fromDate:currentDate];

NSDateComponents *timeComponents = [calender components:(NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit) fromDate:currentDate];

NSDateComponents *temp = [[NSDateComponents alloc]init];

[temp setYear:[dateComponents year]];
[temp setMonth:[dateComponents month]];
[temp setDay:[dateComponents day]];
[temp setHour:[timeComponents hour]];
[temp setMinute:[timeComponents minute]];
[temp setSecond:[timeComponents second] +10];

NSDate *fireTime = [calender dateFromComponents:temp];


UILocalNotification *localN = [[UILocalNotification alloc]init];
localN.fireDate = fireTime;
localN.timeZone = [NSTimeZone defaultTimeZone];


localN.alertBody = @"BLA BLA BLA!";
localN.alertAction = @"GO BACK";


localN.applicationIconBadgeNumber = 1;


[[UIApplication sharedApplication] scheduleLocalNotification:localN];
4

1 に答える 1

4

スケジュールされたすべての通知をキャンセルできます。

[[UIApplication sharedApplication] cancelAllLocalNotifications];

スケジュールされたすべての通知を削除したくない場合 (おそらく何か他のスケジュールが設定されている場合) はcancelLocalNotification:、単一のインスタンスのみをキャンセルできる方法を見てください。

于 2012-11-03T02:31:27.280 に答える