Edujugon / PushNotification

PHP and Laravel Package to send push notifications to Android and IOS devices.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Clean up unregistered devices on notification channels?

scramatte opened this issue · comments

Hi,

I would like to clean up unregistered device tokens from my database on notification channels.

Following code works as expected with manual push message.

        $user = User::where('username', 'abc')->first();

         $tokensApns = $user->pushTokens()->where('type', 'APNS')->pluck('token')->toArray();
        dump($tokensApns);

        $push = new PushNotification('apn');

        $payload = [
                'aps' => [
                        'alert' => 'Hola mundo',
                        'badge' => 1,
                        'sound' => 'default'
                ]
        ];

        $push->setMessage($payload)
              ->setDevicesToken($tokensApns)
              ->send();
        $feedback = $push->getFeedback();
        dump($feedback);

        UserPushToken::whereIn('token', $feedback->tokenFailList)->delete();

But how can I achieve the same thing into "toApn" method ? Moreover my Notifications are queued so where/when/how can I catch invalid tokens ?

Thank you