IOS push notification issue with APNS

101 Views Asked by At

I am trying to send a push notification to an IOS device, the PHP code is as below

$http2ch = curl_init();
curl_setopt($http2ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2_0);
$apnsCert = config('constant.APNS_CERT');
$pushData = [];
$pushData['sound'] = $sound;
$pushData['alert']['title'] = $data['title'];
$pushData['alert']['body'] = $data['message'];
$payload['aps'] = $pushData;
$payload = json_encode($payload);
$http2_server = config('constant.APPLE_NOTIFICATION_API_URL');
$appBundleId = config('constant.APP_BUNDLE_ID');
$token = '<IOS_DEVICE_TOKEN>'
$url = "{$http2_server}/3/device/{$token}";
$headers = array(
    "apns-topic: {$appBundleId}",
    "User-Agent: My Sender",
);
curl_setopt_array($http2ch, [
    CURLOPT_URL => $url,
    CURLOPT_PORT => 443,
    CURLOPT_HTTPHEADER => $headers,
    CURLOPT_POST => true,
    CURLOPT_POSTFIELDS => $payload,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_TIMEOUT => 30,
    CURLOPT_SSL_VERIFYPEER => false,
    CURLOPT_SSLCERT => $apnsCert,
    CURLOPT_HEADER => 1,
]);
$result = curl_exec($http2ch);
curl_close($http2ch);

The above code is completely working fine in the local server (Wamp) while getting Http Code 0 on the server

Can anyone please help to resolve the issue

0

There are 0 best solutions below