首页 > 解决方案 > ios 通知未在 Kreait\Firebase 中接收

问题描述

所有的东西都在 android 上运行完美,但 ios 没有收到来自 php 后端 api 的任何消息。

案例 1:当应用程序处于后台模式时,从这里https://www.pushtry.com/测试时成功在移动应用程序上接收 PN 。

案例 2:下面的 php 脚本即使在后台模式应用程序中也不发送 PN。这是php api代码脚本。

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);
    }
}

}

有人可以帮我指导ios :)

标签: phpfirebasereact-nativeapple-push-notificationsreact-native-push-notification

解决方案


推荐阅读