おはよう、 localNotificationに2週間(14days)ごとに通知する方法。2週間ごとにUILocalNotificationに通知する方法
- (void)applicationDidEnterBackground:(UIApplication *)application {
timer = [NSTimer scheduledTimerWithTimeInterval:60*60*24*14 target:self selector:@selector(getNotifiedForTwoWeeks:) userInfo:nil repeats:YES];
}
-(void)getNotifiedForTwoWeeks:(id)userinfo{
// Schedule the notification
UILocalNotification* localNotification = [[UILocalNotification alloc] init];
localNotification.fireDate = [NSDate date];
localNotification.alertBody = @"Notification Message";
localNotification.alertAction = @"Show me the item";
localNotification.timeZone = [NSTimeZone timeZoneWithName:@"GMT"];
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
}
この実装は正しいかどうかを教えてください。 2週間ごとにLocalNotificationメッセージを通知するための最善の方法がありますか?
貴重なご意見をいただきありがとうございます。
に
fireDate
とrepeatInterval
プロパティを宣言し、14日ごとのスケジュールすることができます2週間。 'fireDate'を将来の日付に更新する必要があります(また、60 * 60 * 24 * 12ではなく、NSCalendar'の計算を行う必要があります)。 http://stackoverflow.com/a/27424355/1271826を参照してください。 – Rob2週間ごとではなく、毎週または毎月であれば、 'repeatInterval'を使うことができますが、2週間ごとに、その答えに示されているように自分でスケジュールを設定する必要があると思います。 – Rob
@NSTimerは、指定された通知宣言メソッドの特定のメソッドをトリガするためにTimeIntervalをスケジュールするために使用されます。 – kiran