I am sending push notification using php code and ios didn't get notification so whats the exact issue i don't know please help.
public static function ios_push($device_token,$title,$msg,$description,$type = "",$r_type = "")
{
\Log::info('device_token', ['context' => $device_token]);
\Log::info($device_token);
$badge_count =2;
$streamContext = stream_context_create();
$connectTimeout = 60;
stream_context_set_option($streamContext, 'ssl', 'passphrase',IPHONE_CERTIFICATE_PASSWORD);
\Log::info(IPHONE_CERTIFICATE_TYPE);
if(IPHONE_CERTIFICATE_TYPE == "Development")
{
//For Development
stream_context_set_option($streamContext, 'ssl', 'local_cert',IOS_PUSH_DEV_PEM_PATH);
$apns = stream_socket_client('ssl://gateway.push.apple.com:2195', $error, $errorString, $connectTimeout, STREAM_CLIENT_CONNECT |STREAM_CLIENT_PERSISTENT, $streamContext);
}
else
{
//For Production
stream_context_set_option($streamContext, 'ssl', 'local_cert',WWW_ROOT_PATH.IOS_PUSH_DEV_PEM_PATH);
$apns = stream_socket_client('ssl://gateway.push.apple.com:2195', $error, $errorString, $connectTimeout, STREAM_CLIENT_CONNECT |STREAM_CLIENT_PERSISTENT, $streamContext);
}
if (!$apns) {
\Log::info('Error : '.$error.' '.$errorString);
} else {
\Log::info("success");
}
$music = 'default';
$payload['aps'] = array('alert' => ['title'=>$title,'body'=>$msg], 'badge' => $badge_count,'title'=>$description,'sound'=> $music , 'notification_type' => $type);
//$payload['aps'] = array('alert' => "vikas", 'badge' => $badge_count,'sound'=> $music , 'notification_type' => $type);
// $data['notification_type'] = $notification_type;
// $data['sender_first_name'] = $sender_first_name;
// $data['sender_last_name'] = $sender_last_name;
// $data['sender_user_id'] = $sender_user_id;
$data['sound'] = $music;
$data['title'] = $title;
$data['notification_type'] = $type;
$data['report_type'] = !empty($r_type) ? substr($r_type, 0, -8) : "";
$payload['data'] = $data;
$payload = json_encode($payload);
\Log::info('Log message', ['payload' => json_encode($payload)]);
$apnsMessage = chr(0) . pack('n', 32) . pack('H*', $device_token) . pack('n', strlen($payload)) . $payload;
$fwriteRes = fwrite($apns, $apnsMessage, strlen($apnsMessage));
fclose($apns);
return true;
}
This is my function
But IOS didn't get any notification in mobile
SO whats the issue
The issue for 2195 port is close thats why?