我在laravel应用上使用https://github.com/davibennun/laravel-push-notification包来获取推送通知。它适用于iOS,但在Android上我遇到过这个问题。打开通知栏时,标题和图标丢失。
你能帮我弄清楚为什么标题没有显示在android上。谢谢!
代码:
$notification_message = PushNotification::Message( $message->message, array(
'badge' => 1,
'actionLocKey' => 'Read new message: '. $message->subject,
'locKey' => $message->subject,
'launchImage' => url($message->image)
));
foreach ($target_devices as $platform => $devices) {
$collection = PushNotification::app($platform)
->to( PushNotification::DeviceCollection($devices) )
->send($notification_message);
// get response for each device push
foreach ($collection->pushManager as $push) {
$response = $push->getAdapter()->getResponse();
// dd($response);
}
}
日志:
object(ZendService\Google\Gcm\Response)[367]
protected 'id' => int 5820913987510378862
protected 'cntSuccess' => int 2
protected 'cntFailure' => int 1
protected 'cntCanonical' => int 1
protected 'message' =>
object(ZendService\Google\Gcm\Message)[357]
protected 'registrationIds' =>
array (size=3)
0 => string 'xxxxx' (length=140)
1 => string 'yyyyy' (length=152)
2 => string 'zzzz' (length=140)
protected 'collapseKey' => null
protected 'data' =>
array (size=4)
'badge' => int 1
'actionLocKey' => string 'Read new message: android test' (length=30)
'locKey' => string 'android test' (length=12)
'message' => string 'android testandroid testandroid testandroid test' (length=48)
protected 'delayWhileIdle' => boolean false
protected 'timeToLive' => int 600
protected 'restrictedPackageName' => null
protected 'dryRun' => boolean false
protected 'results' =>
array (size=3)
0 =>
array (size=1)
'error' => string 'NotRegistered' (length=13)
1 =>
array (size=1)
'message_id' => string '0:1452069848335048%e158bc73f9fd7ecd' (length=35)
2 =>
array (size=2)
'registration_id' => string 'xxxxx' (length=152)
'message_id' => string '0:1452069848336639%e158bc73f9fd7ecd' (length=35)
protected 'response' =>
array (size=5)
'multicast_id' => int 5820913987510378862
'success' => int 2
'failure' => int 1
'canonical_ids' => int 1
'results' =>
array (size=3)
0 =>
array (size=1)
...
1 =>
array (size=1)
...
2 =>
array (size=2)
答案 0 :(得分:1)
刚才意识到我可以传递任何所需的有效负载。所以你可以为android添加标题,副标题,tickerTitle。
$notification_message = PushNotification::Message( $message->message, array(
'badge' => 1,
'actionLocKey' => 'Read new message: '. $message->subject,
'locKey' => $message->subject,
'message' => $message->message,
'title' => $message->subject,
'subtitle' => $message->message,
'tickerText' => 'Read new message: '. $message->subject,
'largeIcon' => 'ionic',
'smallIcon' => 'ionic',
'launchImage' => 'ionic'
));
参考: https://github.com/phonegap/phonegap-plugin-push/blob/master/docs/PAYLOAD.md
答案 1 :(得分:-1)