ローカル通知を使用して発火日をスケジュールしましたが、アプリがバックグラウンドで通知トレイを開いて通知を確認すると、ローカル通知は自動的に発火しますが、発火日は残っています..その問題を解決する解決策はありますか
1 に答える
1
これには、2 つの問題があるようです。まず、ローカル通知は過去に設定された発火日で作成されています。そのため、アプリを開くとすぐに表示されます。
次に、通知の repeatInterval を 0 以外の値に設定している可能性があります。これにより、通知が複数回表示されます。
ローカル通知を午後 3 時に起動するように設定するには、次のコードを参照してください。
UILocalNotification *localNotification = [[UILocalNotification alloc] init];
localNotification.alertBody = @"This is a test alert";
NSCalendar *currentCalendar = [NSCalendar currentCalendar];
NSDateComponents *comps = [[NSDateComponents alloc] init];
[comps setHour: 15];
[comps setMinute: 0];
[comps setSecond: 0];
NSDate *threePM = [currentCalendar dateFromComponents:comps];
// Test if the current time is after three or not:
if(threePM != [threePM earlierDate: [NSDate date]])
{
comps = [[NSDateComponents alloc] init];
[comps setDay: 1];
threePM = [currentCalendar dateByAddingComponents: comps toDate: threePM options: 0];
}
localNotification.fireDate = threePM;
localNotification.repeatInterval = 0;
[[UIApplication sharedApplication] scheduleLocalNotification: localNotification];
于 2012-12-05T10:38:43.200 に答える