【发布时间】:2017-03-16 06:13:24
【问题描述】:
我正在使用这个库:https://github.com/davibennun/laravel-push-notification 来发送推送通知。我使用了示例代码,并且向我的 iPhone 推送消息正在工作。
现在我想向多个设备发送 1 条消息。文档说我需要使用:
$devices = PushNotification::DeviceCollection(array(
PushNotification::Device('token', array('badge' => 5)),
PushNotification::Device('token1', array('badge' => 1)),
PushNotification::Device('token2')
));
$message = PushNotification::Message('Message Text',array(
'badge' => 1,
'sound' => 'example.aiff',
'actionLocKey' => 'Action button title!',
'locKey' => 'localized key',
'locArgs' => array(
'localized args',
'localized args',
),
'launchImage' => 'image.jpg',
'custom' => array('custom data' => array(
'we' => 'want', 'send to app'
))
));
$collection = PushNotification::app('appNameIOS')
->to($devices)
->send($message);
// get response for each device push
foreach ($collection->pushManager as $push) {
$response = $push->getAdapter()->getResponse();
}
但我希望在 devicecollection 上的数据库中有一个 foreach 循环。我如何用 laravel 做到这一点?非常感谢!
【问题讨论】:
-
你的意思是有一个对应设备的数据库列?
-
我的意思是我有一个 for 循环示例: foreach($devices as $device){ $device->token;我想要 DeviceCollection 数组中的令牌
-
请您分享更多代码,我也在努力实现这个库。我正在使用 Laravel 5.5.14
标签: php android ios laravel laravel-5.2