Firebase 클라우드 메시징을 내 애플리케이션에 구현했으며 Firebase 콘솔을 사용하는 동안 Android 및 iOS의 내 애플리케이션에서 내 알림을받습니다. 그러나 매일 알림을 보내려고했기 때문에 내 서버 쪽에서 cron 작업을 만들었습니다. 내 cron 응용 프로그램이 다운 될 때마다 응용 프로그램이 작동하지 않을 때가 있습니다.remoteMessage.getNotification(). getBody()의 오류
내 iOS 클라이언트에서 알림을받지 못합니다. 내 안드로이드 클라이언트에서
이 오류가 표시
java.lang.String com.google.firebase.messaging.RemoteMessage$Notification.getBody()' on a null object reference
가 여기 내 FirebaseMessagingService
에 내 코드
public class MyFirebaseMessagingService extends FirebaseMessagingService {
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
Log.d(TAG, "From: " + remoteMessage.getFrom());
Log.d(TAG, "Notification Message Body: " + remoteMessage.getNotification().getBody());
sendNotification(remoteMessage.getNotification().getBody());
}
입니다 그리고 내 서버 측에서
function sendNotificationFCM($apiKey, $registrationIDs, $messageText,$id) {
$headers = array(
'Content-Type:application/json',
'Authorization:key=' . $apiKey
);
$message = array(
'registration_ids' => $registrationIDs,
'data' => array(
"message" => $messageText,
"id" => $id,
),
);
$ch = curl_init();
curl_setopt_array($ch, array(
CURLOPT_URL => 'https://fcm.googleapis.com/fcm/send',
CURLOPT_HTTPHEADER => $headers,
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POSTFIELDS => json_encode($message)
));
$response = curl_exec($ch);
curl_close($ch);
return $response;
}
왜 NPE가 있고 어떻게 c가되는지 궁금합니다. 나는 그것을 해결합니까?
$ 메시지의 알림 개체는 어디에 있습니까? – mgcaguioa
@sinense'notification' 객체가 없기 때문에'data'만으로 충분하다고 생각합니다. 왜냐하면'notification'은 선택 사항이기 때문입니다. '$ message'에 추가해야합니까? 'notification' 객체에는 무엇을 넣어야합니까? – natsumiyu
예 알림 개체는 기본적으로 선택 사항입니다. 하지만 onMessageReceived()에서는 remoteMessage.getNotification()을 호출하지만 구문 분석 할 알림 개체가 없습니다. – mgcaguioa