2016-06-03 4 views
0

Firebase 콘솔을 사용하여 알림을 보내고 있습니다. 백그라운드에서 알림을 받았지만 전경에서 알림을받지 못했습니다. 문서에서는, 그래서 그것을 추가,하지만 여전히 작동하지 않습니다 AppDelegate application:didReceiveRemoteNotification:을 구현 말했다포 그라운드에서 알림이 표시되지 않음

다음

당신이 UIAlertViewController을 설정하고이를 제시 할 필요가 전경에있는 동안 내 코드

// [START receive_message] 

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo 
fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler { 

// Print message ID. 
NSLog(@"Message ID: %@", userInfo[@"gcm.message_id"]); 

// Pring full message. 
NSLog(@"%@", userInfo); 
} 
// [END receive_message] 
+0

아마도 이런 바보 같은 질문이지만, 당신이 작동하지 않습니다 말할 때, 당신은 당신이 응용 프로그램에서 검토하고 의미 장치가 Xcode 디버거에 연결되어 있고 콘솔에 NSLog 메시지가 표시되지 않는 경우 올바른지 확인하십시오. –

답변

1

입니다 didReceiveRemoteNotification. pushNotification을 예약하는 동안 알림이 표시됩니다. userInfo 당신의 JSON 페이로드를 기반으로

그래서 당신은 코드 다음을 수행 할 필요가

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo 
fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler { 

    // Print message ID. 
    NSLog(@"Message ID: %@", userInfo[@"gcm.message_id"]); 

    // Pring full message. 
    NSLog(@"%@", userInfo); 

    if (application.applicationState == UIApplicationStateActive) 
    { 
     UIAlertController *alertController = [UIAlertController alertControllerWithTitle:[userInfo objectForKey:@"notification.title"] message:[userInfo objectForKey:@"notification.body"] preferredStyle:UIAlertControllerStyleAlert]; 
     [alertController addAction:[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { 

     }]]; 
     [self.window.rootViewController presentViewController:alertController animated:YES completion:nil]; 
    } 
} 
+0

'확인'버튼 만 표시됩니다. 통지의 '제목'과 '본문'을 어떻게 얻을 수 있습니까? – natsumiyu

+0

대신'aps'를 사용했습니다 :) 이제 감사합니다! – natsumiyu