ios notifications not receiving in Kreait\Firebase

293 Views Asked by At

All the things working perfect on android but ios not receiving any message from php backend api.

CASE 1 : successfully receiving PN on mobile app when testing from here https://www.pushtry.com/ when app in background mode.

CASE 2: Below php script not sending PN not even in background mode app. Here is php api code script.

use Kreait\Firebase\Factory;
use Kreait\Firebase\Messaging\CloudMessage;
use Kreait\Firebase\Messaging\Notification;

public function send_push($target_user_id)
{
$fcm_token = get_user_meta($target_user_id, 'fcm_token', true);

if (!empty($fcm_token)) {
    $title = "Your Invitation Was Accepted";
    $body = 'Click here to start game';

    try {
        $message = CloudMessage::withTarget('token', $fcm_token)
            ->withNotification(Notification::create($title, $body))
            ->withData([
                'notification_type' => 'invitation_accepted',
                'title' => $title,
                'body' => "Your partner's accepted your invitation",
            ]);

        $this->messaging->send($message);
    } catch (\Throwable $e) {
        // for PHP 7.x
        $this->on_error($e);
    } catch (\Exception $e) {
        // for PHP 5.x
        $this->on_error($e);
    }
}

}

Can someone please help me to guide for ios :)

0

There are 0 best solutions below