Laravel FCM推送通知不适用于iOS,但适用于Android-Brozot / laravel-fcm

时间:2019-06-17 10:54:16

标签: laravel

Laravel FCM推送通知不适用于iOS,但适用于Android-brozot / laravel-fcm

config(['fcm.http.server_key' => $shop_data->fcm_server_key]);
                config(['fcm.http.sender_id' => $shop_data->fcm_sender_id]);

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

                $notificationBuilder = new PayloadNotificationBuilder($message);
                $notificationBuilder->setBody($message_image)
                    ->setSound('default');

                $dataBuilder = new PayloadDataBuilder();
                $dataBuilder->addData(['message' => trim($message), 'image' => trim($message_image)]);

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

                $device_groups = DeviceGroup::where('shop_id', $shop_id)->get();
                foreach ($device_groups as $device_group) {
                    $groupResponse = FCM::sendToGroup($device_group->group_key, $option, null, $data);
                    $groupResponse->numberSuccess();
                    $groupResponse->numberFailure();
                    $groupResponse->tokensFailed();
                }

3 个答案:

答案 0 :(得分:0)

这是针对iOS的FCM。将其放入特质是一个好主意。不要忘记包括:

jq

答案 1 :(得分:0)

如果您尝试使用ios模拟器,它将无法正常工作。您需要使用testflight或真实设备等工具进行测试。

can we check push notification in simulator?

答案 2 :(得分:0)

您必须使用setContentAvailable(true)向iOS发送静默通知:

$optionBuilder = new OptionsBuilder(); 
$optionBuilder->setContentAvailable(true); 
$optionBuilder->setPriority(OptionsPriorities::normal); 
$dataBuilder = new PayloadDataBuilder(); 
$dataBuilder->addData($data); 
$option = $optionBuilder->build(); 
$data = $dataBuilder->build();

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