2

를 실행하지 않는 나는 때 응용 프로그램은 내가 JSON을 처리하고와 메시지를 구성 할 수 있습니다 실행, 푸시 메시지가 parse.com로 보내 처리에 문제가 :핸들 JSON 푸시 알림 구문 분석 응용 프로그램은

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo 

그러나 응용 프로그램이있는 경우 백그라운드에서 또는 죽은이 메시지는 핸들이며 알림 바에 직접 보냅니다. 나는이 함수에서 처리하려고 :

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
.... 
UILocalNotification *localNotif = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey]; 
    if (localNotif) { 

     [[UIApplication sharedApplication] setApplicationIconBadgeNumber: 99]; 
     UIAlertView *BOOM = [[UIAlertView alloc] initWithTitle:@"BOOM" 
                 message:@"app was INACTIVE" 
                 delegate:self 
              cancelButtonTitle:@"a-ha!" 
              otherButtonTitles:nil]; 
     [BOOM show]; 
     NSLog(@"App was NOT ACTIVE"); 
    } 
..... 

추정이 응답,하지만 난 메시지를 밀어 처리 할 수 ​​없습니다 :

Handling Push Notifications when App is NOT running

Can't handle push notifications when app is running background

Handling push notifications when app is not running (App is Killed)

how can I handle push notification when my app is not running

도움이 필요하십니까? 고마워.

답변

0
I 앱이 실행되지 않거나 배경에, 내가, 내가 안드로이드 응용 프로그램처럼하고있어 해상도의 포커스를 변경하지만 난 아이폰 OS는 "메시지 제어"와 메시지를 처리하고 난하지 알림을 처리 할 수 ​​

이것을 처리하는 "길"을 발견했습니다.

사용자 설정에 따라 구독 메시지의 푸시 알림 채널 을 사용하기 시작합니다. 나는 채널로 메시지를 파싱하고, 앱은 채널을 구독한다.

당신은 POST를 통해 알림을 보낼 수 있습니다

앱에서
curl -X POST \ 
    -H "X-Parse-Application-Id: {APP-KEY}" \ 
    -H "X-Parse-REST-API-Key: {REST-API-KEY}" \ 
    -H "Content-Type: application/json" \ 
    -d '{ 
     "channels": [ 
      "valencia", 
      "sevilla" 
     ], 
     "data": { 
      "alert": "Fin del partido Betis - Valencia 0-2", 
      "sound": "gol.mp3" 
     } 
     }' \ 
    https://api.parse.com/1/push 

당신은 AppDelegate에의 채널을 구독 할 수 있습니다

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)newDeviceToken { 
    // Store the deviceToken in the current installation and save it to Parse. 
    PFInstallation *currentInstallation = [PFInstallation currentInstallation]; 
    [currentInstallation setDeviceTokenFromData:newDeviceToken]; 

    NSArray * channels = @[@"channel1", @"channel2"]; 
    NSLog(@"Channels : %@", channels); 
    currentInstallation.channels = channels; 
    [currentInstallation saveInBackground]; 
} 

당신은 어디서나 채널을 변경할 수 있습니다, 다음과 같이 :

PFInstallation *currentInstallation = [PFInstallation currentInstallation]; 
currentInstallation.channels = @[@"channel3"]; 

[currentInstallation saveInBackground]; 

아마도 누군가를 도울 수 있습니다.

-1

앱이 종료되고 푸시 알림을 받으면이 기능에 코드를 추가하십시오.이 기능을 호출하여이 알림에서 앱을 다시 실행하고 이에 따라 애플리케이션에서 알림을 표시 할 수 있습니다.

(void)application:(UIApplication *)app didReceiveRemoteNotification:(NSDictionary *)userInfo 
+0

응용 프로그램이 실행 중일 때이 함수를 사용하면 JSON을 가져 와서 메시지를 만들 수 있습니다. 내 문제는 앱이 실행되고 있지 않을 때입니다. – fermin

+0

앱이 실행되지 않을 때도이 기능이 계속 호출되지만 로컬 알림을 활성화하고 애플리케이션에 경고를 표시하려면 앱을 강제 중지 상태로 만들 때 애플리케이션을 다시 실행해야합니다. 애플리케이션 코드를 사용하여 경고를 표시 할 수 없습니다. –

+0

앱을 제거한 다음 다시 설치해보세요.하지만 동일한 문제가 있습니다. 표시 할 메시지를 다시 작성하지만이 기능에 대해 실행되지 않았습니다. – fermin

관련 문제