我正在使用此库: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做到这一点?非常感谢!
答案 0 :(得分:1)
foreach($usersApple as $userApple){
echo $userApple->reg_id . '<br>';
$deviceslist[] = PushNotification::Device($userApple->reg_id);
}
$devices = PushNotification::DeviceCollection($deviceslist);
已经修好了,今天不是很尖锐哈哈