【问题标题】:Laravel push notificationsLaravel 推送通知
【发布时间】: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


【解决方案1】:
foreach($usersApple as $userApple){
                echo $userApple->reg_id . '<br>';
                $deviceslist[] = PushNotification::Device($userApple->reg_id);
            }

            $devices = PushNotification::DeviceCollection($deviceslist);

已经修好了,今天不锋利哈哈

【讨论】:

    猜你喜欢
    • 2018-02-17
    • 1970-01-01
    • 2022-07-16
    • 1970-01-01
    • 2019-11-11
    • 2021-11-04
    • 2019-12-15
    • 1970-01-01
    • 2020-11-04
    相关资源
    最近更新 更多