local notifications
私のアプリケーション で有効にするのはかなり困難でした。
そして、ええ、アプリが1週間local notification
閉じられた後にスケジュールしたい魔女とプロジェクトをセットアップしました. たとえば、ユーザーが土曜日の 8 日にアプリを開いた場合、ローカル通知は次の土曜日の 15 日に表示されますが、時刻は変更されます。たとえば、彼/彼女は午後 8 時にアプリを閉じますが、来週の午後 8 時に邪魔したくないので、すべての通知を午後 6 時に表示したいなどです。
これで私の問題がわかりました。これが私が使用しているコードです。
- (void)applicationDidEnterBackground:(UIApplication *)application
{
[[UIApplication sharedApplication] cancelAllLocalNotifications];
NSCalendar *calendar = [NSCalendar autoupdatingCurrentCalendar] ;
NSDateComponents *componentsForReferenceDate = [[NSDateComponents alloc] init];
//set day (saturday)
[componentsForReferenceDate setDay:26] ;
[componentsForReferenceDate setMonth:1] ;
[componentsForReferenceDate setYear:2013] ;
[componentsForReferenceDate setHour: 17] ;
[componentsForReferenceDate setMinute:30] ;
[componentsForReferenceDate setSecond:00] ;
NSDate *fireDateOfNotification = [calendar dateFromComponents: componentsForReferenceDate];
// Create the notification
UILocalNotification *notification = [[UILocalNotification alloc] init] ;
notification.fireDate = fireDateOfNotification ;
notification.timeZone = [NSTimeZone localTimeZone] ;
notification.alertBody = [NSString stringWithFormat: @"Du wirst vermisst! \nDeine App braucht dich, schreibe sie zu Ende!"] ;
notification.alertAction = @"Zurückkehren";
notification.userInfo= [NSDictionary dictionaryWithObject:[NSString stringWithFormat:@"Some information"] forKey:@"information"];
notification.repeatInterval= NSWeekCalendarUnit ;
notification.soundName = @"Appnotifisound.wav";
notification.applicationIconBadgeNumber = 1;
[[UIApplication sharedApplication] scheduleLocalNotification:notification] ;
}
バッジと を削除する方法が他にもある必要があることはわかっていますが、これには重要ではないdidrecievenotification
ため、それらを除外しました。
このコードを使用して、毎週土曜日の午後 5 時 30 分(ドイツ) に通知をスケジュールすることができました。しかし、アプリがちょうど1週間閉じられたときに、一度だけスケジュールしたかったのです。それはどういうわけか可能ですか?誰かが私のコードを修正するか、これに対する解決策を教えていただければ幸いです。
よろしくお願いします。この長い投稿を読んでいただきありがとうございます。
ノア