Just use GuzzleHttp\Client and we don't need JWT. See the working code-
$url = "api.sandbox.push.apple.com/3/device/";
$headers = array( "apns-topic: com.example.exampleapp", "apns-push-type: alert", "Content-Type: application/x-www-form-urlencoded", );
$certificate_file = "iosCertificates/apple-push-dev-certificate-with-key.pem";
$payloadArray['aps'] = [ 'alert' => [ 'title' => "Test Push Notification", 'body' => "Ohhh yeah working", ], 'sound' => 'default', 'badge' => 1
];
$data = json_encode($payloadArray);
$client = new Client();
$response = $client->post($url, [ 'headers' => $headers, 'cert' => $certificate_file, 'curl' => [ CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_2_0, ], 'body'=> $data,
]);
I tries this. Getting following error: Fatal error: Uncaught GuzzleHttp\Exception\ConnectException: cURL error 7: Failed to connect to api.sandbox.push.apple.com port 80: Connection timed out Am I missing anything here?
This is the correct answer. I was able to use this to send Safari Web Push Notifications.
Ensure that you include the device token in the URL: $url = "api.sandbox.push.apple.com/3/devic...", otherwise it won't work.
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Just use GuzzleHttp\Client and we don't need JWT. See the working code-
$url = "api.sandbox.push.apple.com/3/device/";
$headers = array(
"apns-topic: com.example.exampleapp",
"apns-push-type: alert",
"Content-Type: application/x-www-form-urlencoded",
);
$certificate_file = "iosCertificates/apple-push-dev-certificate-with-key.pem";
$payloadArray['aps'] = [
'alert' => [
'title' => "Test Push Notification",
'body' => "Ohhh yeah working", ],
'sound' => 'default',
'badge' => 1
];
$data = json_encode($payloadArray);
$client = new Client();
$response = $client->post($url, [
'headers' => $headers,
'cert' => $certificate_file,
'curl' => [
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_2_0,
],
'body'=> $data,
]);
I tries this. Getting following error:
Fatal error: Uncaught GuzzleHttp\Exception\ConnectException: cURL error 7: Failed to connect to api.sandbox.push.apple.com port 80: Connection timed out
Am I missing anything here?
This is the correct answer. I was able to use this to send Safari Web Push Notifications.
Ensure that you include the device token in the URL:
$url = "api.sandbox.push.apple.com/3/devic...", otherwise it won't work.