2012-03-15 2 views
0

내가 좋아하는 쓴 : 나는 매 5 분 내 타이머를 반복합니다 의미문제는

[NSTimer scheduledTimerWithTimeInterval:900 target:self selector:@selector(CallGetCounts) userInfo:nil repeats:YES]; 

하지만 내 타이머는 이유를 찾을 수 없습니다, 반복되지

수있는 하나는 대답을 말해주십시오.

""-> "- (void)applicationDidEnterBackground:(UIApplication *)application"방법으로 작성했습니다.

+0

내가 테스트 : 여기

는 그 방법의 일부 단계는 "[NSTimer scheduledTimerWithTimeInterval 1.0 대상 : 자기 선택기 : @ 선택기 (CallGetCounts) 유저 정보 : 반복 닐 : YES];" 또한 그 시간에 타이머가 반복되지 않습니다 – user1179681

+0

어떤 종류의 객체가'self'입니까? 그것은 공개 되는가? 실제로'CallGetCounts' 메소드에 응답합니까? 코드를 볼 수 있습니까? – jtbandes

+0

"AppDelegate"-> "- (void) applicationDidEnterBackground : (UIApplication *) application"메서드에서이 코드를 작성했습니다. – user1179681

답변

2

백그라운드에서 코드가 일시 중단되었으며 응용 프로그램이 포 그라운드로 다시 전달 될 때까지 타이머 이벤트가 수신되지 않습니다.

일정한 간격 후에 백그라운드에서 깨우기 위해 예정된 지역 알림을 찾아야합니다. 그러나 사용자가 먼저 수락해야하는 팝업 또는 배너를 표시합니다.

// When you want to schedule: 
UILocalNotification* localNotification = [[[UILocalNotification alloc] init] autorelease]; 
localNotification.fireDate = [NSDate dateWithTimeIntervalSinceNow:5]; // seconds 
localNotification.timeZone = [NSTimeZone defaultTimeZone]; 
localNotification.alertBody = @"Body text"; 
localNotification.alertAction = @"Button text"; 
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification]; 

// when it's fired it will call your AppDelegate's didReceiveLocalNotification 
- (void)application:(UIApplication *)app didReceiveLocalNotification:(UILocalNotification *)localNotification 
{ 
    // you can handle timer event here and eventually re-schedule your local notification 
} 
1

일반적으로 앱이 백그라운드로 들어가면 앱이 일시 중지되어 전혀 실행되지 않습니다. 특히 NSTimers는 작동하지 않습니다. 백그라운드에서 어떤 일이 일어나길 원한다면 백그라운드에서 실행되도록 앱을 구성하고 승인 된 작업 수행 방법 중 하나를 사용해야합니다. NSTimers를 실행하는 것은 지원되는 작업 중 하나가 아닙니다.

iOS 프로그래밍 가이드, 특히 Background Execution and Multitasking 섹션을 읽어 보시기 바랍니다.

1

UILocalNotification의 인스턴스는 팝업 상자를 발생 (당신의 응용 프로그램을 깨울) 당신이 정말로 Here이 S.O 스레드에서 논의 된 좋은 튜토리얼 링크입니다 다음 UILocalNotification을 선택하면, 당신은 설정 한 시간에 따라 트리거 할 때마다. 그 사람들이 당신을 도울 수 있기를 바랍니다.