iPhone push-notification works in sandbox but not in production mode

14,457

Solution 1

Here is three cases you can check at your end:-

  1. Make sure that you have used the right production certificate on your server side. since we need to create two different certificates for production and sandbox. make sure you are using correct certificate on server.

  2. second you can check that you have use the right gateway and port number on server side. Since gateway for production and sandbox are different one. Gateway used for production is:- gateway.push.apple.com. and also you are using correct password on server for your certificate your have used on your server.

  3. third you can check if the notification on your device is enabled or not. You need to enable it on your iPhone as well. Make sure that is on your device.

Let me know if it works for you.

Solution 2

For me, i struggle this for days. Using correct production certificate and key, and also correct gateway to send the message to my developing iPhone, it sent successfully in sandbox mode, but failed with production mode. It's because there are also two kinds of device token, the testing iPhone device token is sandbox token, can not be used in the production mode. It's better to use another device's token to test the production APNs.

The detailed explanation is here

The most common problem is an invalid device token. If the token came from the sandbox environment, such as when you are testing a development build in house, you cannot send it to the production push service. Each push environment will issue a different token for the same device or computer. If you do send a device token to the wrong environment, the push service will see that as an invalid token and discard the notification.

Solution 3

See answer in https://stackoverflow.com/a/11623162/496222

In short: make sure both SSL certificates are in a separate PEM file. Having a single PEM file with both sandbox and production certificate will cause either environment to fail.

Share:
14,457
Swissdude
Author by

Swissdude

Updated on June 26, 2022

Comments

  • Swissdude
    Swissdude about 2 years

    As the title says, I have an app with built in APNS. It does work perfectly in Sandbox-mode. But in production-mode, it fails miserably.

    It seems that I have the right certificates on the server, because I don't get an error back from the APNS-Service. Everything seems to work fine. I am using ApnsPHP by Aldo Armiento. It has a built-in function to spit out the results from the APNS-Server. When I try to use the Sandbox with the app from the store, I get - as expected - an invalid-token-error (since tokens from sandbox and production are different). When I use the production-certificate with the app from the store, I don't get an error. Nothing, nada, zilch - it seems like it delivered the notification. Alas, it doesn't arrive on my phone.

    So apparently, the certificates must be ok. It connects to the server, it sends the notification, all passes without errors (I did have wrong certificates first, so I know what happens if they're not right :)

    Any ideas how to find out where the bug hides?

    [Edit] here's what I get back from the APNS-Service:

    Tue, 03 Jan 2012 03:13:55 +0100 ApnsPHP[13049]: INFO: Trying ssl://gateway.push.apple.com:2195...
    Tue, 03 Jan 2012 03:13:56 +0100 ApnsPHP[13049]: INFO: Connected to ssl://gateway.push.apple.com:2195.
    Tue, 03 Jan 2012 03:13:56 +0100 ApnsPHP[13049]: INFO: Sending messages queue, run #1: 1 message(s) left in queue.
    Tue, 03 Jan 2012 03:13:56 +0100 ApnsPHP[13049]: STATUS: Sending message ID 1 [custom identifier: Message-Badge-000] (1/3): 107 bytes.
    Tue, 03 Jan 2012 03:13:56 +0100 ApnsPHP[13049]: INFO: Disconnected.
    
  • Swissdude
    Swissdude over 12 years
    Thanks - but I checked all that. Everything's set up the way it's supposed to be. And as mentioned, I don't get any errors from the push-service, it appears as the messages went through... very strange.
  • Sandeep Dhama
    Sandeep Dhama over 12 years
    have you tried to create the production certificate again and put that on your server?
  • Swissdude
    Swissdude over 12 years
    Shame on me :) it was the certificate. I develop for another company and the original developer left - his certificate somehow still seems to be active (I replaced it with mine, though). So the certificate was valid and it was valid for the app. But the binary was compiled with my private key, that must've made the confusion. Thanks for your help!
  • Federico
    Federico about 11 years
    I am having a problem with this too... I got push notifications working on development, but they won't work on live/production. Could you elaborate a bit on that last comment? "the binary was compiled with my private key" ?? I sign the code with a distribution provisioning profile that has push notification permissions, but my production ssl .pem key has nothing to do with building the app. (right?)
  • Swissdude
    Swissdude almost 10 years
    Turns out - I have the same problem as you have. It works in dev/adHoc mode, but the distribution from the app store refuses to receive push-notifications. It seems, the iPhone is no longer sending its credentials to the server that hosts the PHP script to send out the PNs. As I developed it with Cordova and some plugins from IBM-Bluemix, I have no idea what could go wrong...
  • bottus
    bottus almost 7 years
    This man got it dead right .. Thanks for sharing this information.
  • Nick
    Nick over 6 years
    I think this seems to be for Google Cloud Messaging? developers.google.com/cloud-messaging/ios/client
  • LineDrop
    LineDrop about 3 years
    Second that, you are spot on. Thanks! Once a device token has been used in the sandbox (api.sandbox.push.apple.com) request, make sure to reboot the phone and reinstall the app to get get a new device token before testing in the production environment (api.push.apple.com).