即使是ios也可以从fcm控制台获得通知。
控制器功能:
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" : []
}
答案 0 :(得分:0)
如果您尝试使用ios模拟器,它将无法正常工作。您需要使用testflight或真实设备等工具进行测试。
我们可以在模拟器中检查推送通知吗?
答案 1 :(得分:0)
您必须为Ios设置证书,请点击此链接以查看更多详细信息 Configuring APNs with FCM