안녕하세요, localNotification에 2 주 (14 일)마다 알림을 보내는 방법.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 일 동안 예약 할 수 있습니다 이주. 'fireDate'를 미래의 날짜로 업데이트해야합니다. 60 * 60 * 24 * 12가 아닌 'NSCalendar'의 계산을 수행해야합니다. http://stackoverflow.com/a/27424355/1271826을 참조하십시오. – Rob2 주에 한 번씩 매주 또는 매주마다'repeatInterval'을 사용할 수 있습니다. 그러나 매 2 주마다 그 답변에 나와있는 것처럼 스스로 스케쥴해야한다고 생각합니다. – Rob
@NSTimer는 지정된 알림 메서드에 대해 특정 메서드를 트리거하도록 TimeInterval을 예약하는 데 사용됩니다. – kiran