Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Apple Push Notifications if you can't use port 2195?

I have developed a script using stream_socket_client() and it works on my localhost but when I try to use it online (with Fatcow.com web hosting) it won't work. I receive the following error:

Warning: stream_socket_client() [function.stream-socket-client]: unable to connect to ssl://gateway.sandbox.push.apple.com:2195 (Connection refused) in .../send-notification.php on line 18 Failed to connect 111 Connection refused

This is line 18:

$fp = stream_socket_client('ssl://gateway.sandbox.push.apple.com:2195', $err, $errstr, 60, STREAM_CLIENT_CONNECT, $ctx);

I know that the password for the .pem file is correct. The question becomes if I can't use this port what do I do? Is there any free service that I can use? I know that port 80 is open.

I've heard that using the curl() function will work but have been unsuccessful so far.

I would really appreciate getting pointed in the right direction.

like image 510
John Doe Avatar asked Oct 16 '13 02:10

John Doe


People also ask

What port do push notifications use?

Android. Port 443 (HTTPS only)

How do I use Apple push notifications for APN?

Use the location push type for notifications that request a user's location. If you set this push type, the apns-topic header field must use your app's bundle ID with . location-query appended to the end. For more information, see Creating a Location Push Service Extension.

How do I fix Apple push notifications?

You can fix an iPhone that's not getting notifications by restarting it or making sure notifications are turned on. You should also make sure your iPhone is connected to the internet so apps can receive notifications. If all else fails, you should try resetting the iPhone — just make sure to back it up first.

Which external ports do I need to open on my firewall for the push and the APNs MDM functionalities this question is required *?

Check required ports and hostsTCP port 443 or 2197 to send notifications to APNs.


2 Answers

In order to send the notifications to the device need to enable 2195 port in the firewall. For security reasons some organizations disabling these ports in the firewall. 2196 port is used for feedback services and this port also should open in the firewall. Without opening these ports messages cannot deliver to APNS.

like image 142
Ganesh Avatar answered Oct 13 '22 10:10

Ganesh


I believe the following is what you are looking for

$url = 'https://gateway.sandbox.push.apple.com:2195';
$cert = 'AppCert.pem';

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json"));
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_SSLCERT, $cert);
curl_setopt($ch, CURLOPT_SSLCERTPASSWD, "passphrase");
curl_setopt($ch, CURLOPT_POSTFIELDS, '{"device_tokens": ["458e5939b2xxxxxxxxxxx3"], "aps": {"alert": "test message one!"}}');

$curl_scraped_page = curl_exec($ch);

more information can be found here: Apple push notification with cURL

like image 24
Liam Sorsby Avatar answered Oct 13 '22 10:10

Liam Sorsby