2012-12-04 4 views
0

푸시 알림 수신시 작업을 수행하려고합니다. 나는 - (void)application:(UIApplication*)application didReceiveRemoteNotification:(NSDictionary*)userInfo 방법으로 코드를 썼다. 응용 프로그램이 포 그라운드에있을 때 제대로 작동하지만 응용 프로그램이 백그라운드에있을 때 위의 메서드는 호출되지 않습니다. 응용 프로그램이 백그라운드에있을 때이 메서드를 호출 할 수있는 방법이 있습니까? 이 응용 프로그램은 아이튠즈에 제출하는 것이 아니므로 좋은 해킹 트릭? ;)백그라운드에서 푸시 알림을 수신 할 때 작업 수행

+0

이 기능이 작동하는지 여부를 친절히 알려주십시오. –

답변

0

응용 프로그램이 백그라운드에서 실행될 때마다 모든 알림이 backgound 스레드에서 발생하기 시작합니다. 그래서 이런 식으로해야합니다.

... 
[[NSNotificationCenter defaultCenter] addObserver:self  
             selector:@selector(processNotificationInBackground:) 
              name:TheNameOfTheNotification 
              object:nil]; 
... 

- (void) processNotificationInBackground:(NSNotification *)not { 
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ 
     /* your background notification processing code goes here */ 
     /* note that you should transfer control back to the main queue if you need to update your UI */ 
    } 
} 
+0

그것은 나를 위해 작동하지 않습니다 : ( –

+0

당신이 통지 생성 및 관찰 및 선택기 호출 여부를 추적 했습니까? –

+0

예, 여기서 선택기가 호출되지 않습니다, 나는 "[[NSNotificationCenter defaultCenter] postNotificationName : TheNameOfTheNotification 개체 : self]; " –

관련 문제