5

I have done apns code for php and objective c from this Apns code

and setup certificate from this link

Sandbox and production apns for sending notification to ios devices is working perfectly on my server.I moved code and same certificate to client server then sending notification is not working.

I debug all php code and found that it stops at this line of code

private function _connectSSLSocket($development) {
    $ctx = stream_context_create();
    stream_context_set_option($ctx, 'ssl', 'local_cert', $this->apnsData[$development]['certificate']);
    $this->sslStreams[$development] = stream_socket_client($this->apnsData[$development]['ssl'], $error, $errorString, 100, (STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT), $ctx);
    if(!$this->sslStreams[$development]){
        $this->_triggerError("Failed to connect to APNS: {$error} {$errorString}.");
        unset($this->sslStreams[$development]);
        return false;
    }
    return $this->sslStreams[$development];
}

apns.log file shows the error "Failed to connect to APNS: 110 Connection timed out."

Not getting the mistake. Why this error am i getting and not sending notification to ios devices ? Can anyone guide me for this ?

Viral Narshana
  • 1,793
  • 2
  • 20
  • 43
  • Your client's server may be behind a firewall that blocks port 2195. – Eran Sep 26 '13 at 10:24
  • http://stackoverflow.com/questions/18085086/apple-push-notification-service-connection-through-proxy-timed-out-with-stream same problem not resolved caused by a proxy server, the only way we found was to permits direct connections to apns – Lucabro Sep 26 '13 at 12:34
  • 3
    ah a problem like this will occur when you are in a shared hosting too – Lucabro Sep 26 '13 at 12:43
  • Thanks to all for comment. Yes i have shared hosting. Any solution for that ? – Viral Narshana Sep 26 '13 at 13:09
  • 1
    Try to looking for a VPS or an external service for push notification like http://push.io/ or http://www.pushwoosh.com/ or http://openpush.im/ – Lucabro Sep 26 '13 at 13:21
  • Luca Machettelodicoaff Brognar is push notification will not work with shared hosting ? I can't use external service and can't move client server to vps. Is any solution with shared hosting ? – Viral Narshana Sep 27 '13 at 04:46
  • Possible duplicate of [stream\_socket\_client unable to connect (connection timed out)](http://stackoverflow.com/questions/1769189/stream-socket-client-unable-to-connect-connection-timed-out) – Heitor May 28 '16 at 06:58

2 Answers2

4

Finally i took vps instead of shared hosting. Lucabro's comments helped me to solve. Thanks Lucabro.

Viral Narshana
  • 1,793
  • 2
  • 20
  • 43
0

A good solution is to use a cloud function like firebase to run the actual apns connection and expose an API for your other backend in the shared hosting. This is what I used when I run in this problem.

Firebase cloud functions are convenient easy to develop and virtually free.

https://firebase.google.com/docs/functions

I'll post my solution to sometimes next week.