【发布时间】:2018-05-06 02:11:12
【问题描述】:
我有一个 Laravel API,它通过 FCM 使用 laravel-push-notifications 框架发送推送通知。在我的本地主机中,我收到带有数据有效负载的消息,但在生产模式下,相同的代码在接收消息时返回有效负载 null。
这是 Laravel 中发送推送通知的方法:
public static function sendPushNotification($deviceToken, $actionId, $text) {
$deviceToken = (string) $deviceToken;
try {
$message = \PushNotification::Message($text, array(
'badge' => 1,
'sound' => 'default',
'content-available' => 1,
'custom' => array(
'registerID' => 'teste',
'fromAPI' => true,
'action' => $actionId
),
'payload' => array(
'notification' => array(
'action' => $actionId,
'title' => $text
),
),
));
if (strlen($deviceToken) > 64) {
$returnAndroid = \PushNotification::app('appJurAndroid')
->to($deviceToken)
->send($message);
} else {
$returnIos = \PushNotification::app('appJurIOS')
->to($deviceToken)
->send($message);
}
} catch (AdapterException $e) {
Log::error("Push notification failure: {$e->getMessage()}");
}
}
在我的 Android 应用中,调用 FCM 委托方法时:
public void onMessageReceived(RemoteMessage remoteMessage)
remoteMessage.getData() 或 remoteMessage.getNotification() 为空。
【问题讨论】:
标签: php android laravel push-notification firebase-cloud-messaging