0

I have been trying for the past how long to figure out how to go from the sandbox APNS to production APNS. Below is the PHP code used to send notifications to my app.

$passphrase = 'SomethingStrong';

$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', $_SERVER['DOCUMENT_ROOT'] . '/ck.pem');
stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);

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

if (!$fp)
{
    //return json_encode(array('response' => 'connection_fail'));
}

$body['aps'] = array(
    'alert' => $message,
    'sound' => 'default'
    );

$payload    = json_encode($body);
$msg        = chr(0) . pack('n', 32) . pack('H*', $deviceToken) . pack('n', strlen($payload)) . $payload;

$result     = fwrite($fp, $msg, strlen($msg));

if (!$result)
    return json_encode(array('response' => 'unsuccessful'));
else
    return json_encode(array('response' => 'successful'));

fclose($fp);

This whole thing works when I keep the URL ssl://gateway.sandbox.push.apple.com:2195, but when I when I change it to ssl://gateway.push.apple.com:2195 no notifications come through my app, yet PHP outputs that it was sent successfully.

I'm code-signing with the development certificates.

I'm new to notifications and have never used them before, so sorry if I'm doing something really obvious. Thanks.

Alec
  • 919
  • 2
  • 10
  • 25

3 Answers3

1

There are two things, you need to confirm:

  • You generate your build with distribution provisioning profile
  • You use production pem file for sending PUSH from your PHP server

Push Notification Certificate

gunjot singh
  • 2,578
  • 20
  • 28
  • I can't build with the distribution profile and run it on my phone. How do I do that? I can only run the development profile. – Alec Mar 03 '16 at 04:51
  • You should be able to do that. When you will run with your app from Xcode with your distribution profile, it would get installed but won't run the first time. Open your app again from home screen, and you have distribution build installed. Or you can simply create a ipa file with distribution profile, and install it in your device. or if you are facing some other error, please do tell. – gunjot singh Mar 03 '16 at 04:57
  • I keep getting this... "The entitlements specified in your application’s Code Signing Entitlements file do not match those specified in your provisioning profile. (0xE8008016)." – Alec Mar 03 '16 at 05:05
  • http://stackoverflow.com/questions/22625785/entitlements-file-do-not-match-those-specified-in-your-provisioning-profile-0xe – gunjot singh Mar 03 '16 at 05:26
  • None of that is working. I did all the certificate stuff right, but when I build for distribution I can't put it on my phone. I can put the developer code-signing on the phone, but I still need sandbox in the PHP code. – Alec Mar 03 '16 at 05:37
  • Should I release the distribution code-signed app to the App Store and see if it works or not when it's live? – Alec Mar 03 '16 at 05:37
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/105215/discussion-between-gunjot-singh-and-alec). – gunjot singh Mar 03 '16 at 06:21
0

You are setting the correct ssl socket ssl://gateway.push.apple.com:2195 for production.

Check the certificates or the ck.pem file you have upload to server should be production.

Also check for the provisioning profile which you select for build should be Distribution profile.

Rahul
  • 241
  • 1
  • 12
  • I can't build with the distribution profile and run it on my phone. How do I do that? I can only run the development profile. – Alec Mar 03 '16 at 04:52
  • http://stackoverflow.com/questions/25056144/xcode-6-how-to-pick-signing-certificate-provisioning-profile-for-ad-hoc-distri – Rahul Mar 03 '16 at 06:18
0

Everything was setup correctly, but I had an issue with my Ad Hoc profile and the way it was code-signing. All is good now! Thanks!

Alec
  • 919
  • 2
  • 10
  • 25