laravel fcm推送通知与brozot/Laravel-FCM在ios上不起作用,但在android上工作正常 [英] laravel fcm push notification with brozot/Laravel-FCM not working on ios but working fine with android

查看:232
本文介绍了laravel fcm推送通知与brozot/Laravel-FCM在ios上不起作用,但在android上工作正常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

即使ios也可以从fcm控制台获取通知.

Even ios can get notification from fcm console.

控制器功能:

public function push(Request $request)
{
    $validator = Validator::make($request->all(), [
        'title' = > 'required',
            'body' = > 'required',
            'token' = > 'required',
            'type' = > 'required',
            'id' = > 'required',

    ]);

    if ($validator->fails()) {
        $this->throwValidationException(
            $request, $validator
        );
    }

    $title = $request['title'];
    $body = $request['body'];
    $type = $request['type'];
    $id = $request['id'];
    $dataarray = array(
        "id" = >$id,
        "type" = >$type,
        'title' = >$title,
        'body' = >$body,
        'image' = >'321451_v2.jpg',
    );

    $token = $request['token'];

    return $push = Push::sendpush($title, $body, $dataarray, $token);

}

push model function :
public static function sendpush($title, $body, $dataarray, $token)
{


    $optionBuiler = new OptionsBuilder();
    $optionBuiler->setTimeToLive(60 * 20);

    $notificationBuilder = new PayloadNotificationBuilder($title);
    $notificationBuilder->setBody($body)
        ->setSound('');

    $dataBuilder = new PayloadDataBuilder();
    $dataBuilder->addData($dataarray);

    $option = $optionBuiler->build();
    $notification = $notificationBuilder->build();
    $data = $dataBuilder->build();

    $token = $token;

    $downstreamResponse = FCM::sendTo($token, $option, $notification, $data);

    return new JsonResponse(array('status' = >'1', 'sucess' = >$downstreamResponse->numberSuccess(), 'fail' = > $downstreamResponse->numberFailure(), 'msg' = >$downstreamResponse->tokensWithError()), 200);

}

Response:
{
    "status": "1",
    "sucess" : 0,
    "fail" : 1,
    "msg" : []
}

推荐答案

您必须为Ios设置证书,请点击此链接以查看更多详细信息 使用FCM配置APN

You have to set up a certificate for Ios follow this link to see more details Configuring APNs with FCM

或查看此在iOS上设置Firebase Cloud Messaging客户端应用

这篇关于laravel fcm推送通知与brozot/Laravel-FCM在ios上不起作用,但在android上工作正常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆