2016-08-15 3 views
-1

안녕하세요, 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 메시지를 알리는 데 최선의 방법을 사용할 수 있습니까?

귀중한 의견을 보내 주시면 감사하겠습니다.

+0

fireDaterepeatInterval 속성을 선언 할 때마다 14 일 동안 예약 할 수 있습니다 이주. 'fireDate'를 미래의 날짜로 업데이트해야합니다. 60 * 60 * 24 * 12가 아닌 'NSCalendar'의 계산을 수행해야합니다. http://stackoverflow.com/a/27424355/1271826을 참조하십시오. – Rob

+0

2 주에 한 번씩 매주 또는 매주마다'repeatInterval'을 사용할 수 있습니다. 그러나 매 2 주마다 그 답변에 나와있는 것처럼 스스로 스케쥴해야한다고 생각합니다. – Rob

+0

@NSTimer는 지정된 알림 메서드에 대해 특정 메서드를 트리거하도록 TimeInterval을 예약하는 데 사용됩니다. – kiran

답변

0

앱이 백그라운드로 들어가면 일정 시간 후 시스템이 일시 중지되고 NSTimer이 예약되지 않습니다. 그래서 당신은 통지를 통해 그에만 응용 프로그램이 활성 인 경우 일 것 같은 나는이`NSTimer`가 무엇인지 확실하지 않다 UILocalNotification

UILocalNotification* localNotification = [[UILocalNotification alloc] init]; 
localNotification.fireDate = [NSDate dateByAddingTimeInterval:60*60*24*14]; 
localNotification.alertBody = @"Notification Message"; 
localNotification.alertAction = @"Show me the item"; 
localNotification.timeZone = [NSTimeZone timeZoneWithName:@"GMT"]; 
localNotification.repeatInterval = NSDayCalendarUnit; 

[[UIApplication sharedApplication] scheduleLocalNotification:localNotification]; 
+0

말할 필요도없이, 'beginBackgroundTaskWithName'는 60 * 60 * 24 * 14로 예정된 타이머와 관련해서는 쓸모가 없습니다. 어쨌든 전체 타이머 문제는이 사용 사례의 막 다른 길입니다. 몇 분이 아니고 몇 분이면 좋을 것입니다. – Rob

+0

네가 맞다. – iSashok

관련 문제