带通知徽章的推送通知

时间:2018-11-12 09:05:38

标签: laravel push-notification pusher

我将向应用程序发送推送通知,我也想发送带有如下所示的推送通知的徽章,但是通知徽章无法正常工作,所以请帮助我弄清楚

公共函数addLike(Post $ post) {    $ authUser = JWTAuth :: parseToken()-> toUser();

$ authUser-> like($ post);

    if ($post->user_id != $authUser->id) {
        $user = User::where('id', $post->user_id)->first();


        $badgeNotification = $user->unreadNotifications->count();           
        // dd($badgeNotification);

        $push = new PushNotification('apn');
        $push->setMessage([
            'aps' => [
                'alert' => $authUser->username.' like your post "'.$post->post_content.'"',
                'sound' => 'default',
                'badge' =>  $badgeNotification
            ],
            'extraPayLoad' => [
                'custom' => 'My custom data',
            ]
        ]);
        $push->setDevicesToken($user->deviceToken);
        $push->send();
        $feedback = $push->getFeedback();

        $user->notify(new LikePost($authUser, $post));
    }

0 个答案:

没有答案