APNS Push Notifications Not Working on Production
Asked Answered
U

4

26

I created an App to send remote notifications from a web server. When I tested the App in Development Mode all the notifications arrived correctly on the phone, after the AppStore release the app did not receive notifications anymore.

Here it is what I did:

  1. Created a Private Key For Production and one for development.
  2. Generated on my App ID two SSL Certificates by passing the previous CertFile Generated. I'm 100% sure to have generated correctly 2 key and passed them correctly to download the SSL Cert from Dev Center under AppID.
  3. Created a file .pem for development and one for production (by converting the file .p12 extracted from my KeyChain etc etc).
  4. Created 2 different provisioning profile one for development and one for production connected to the AppID of step 1.
  5. Signed the app in Build Settings with the correct Provisioning Profiles created in step 4.
  6. Created a Web App to catch and store users Tokens.
  7. Created a php page to test Push Notification Sending.

Here it is what i tested:

  1. Tested the development generated .pem file with telnet on sandbox link with a succesfull answer.
  2. Tested the production generated .pem file with telnet on production link with a succesfull answer.
  3. I'm 100% sure to have stored on my web app the development token of my iPhone.
  4. I'm 100% sure to have stored on my web app server the production token of my iPhone.
  5. I'm 100% sure to pass with my php page the right message to Apple Server (both for development and production).
  6. The php page always return a succesfull message from Apple Server (both for development and production).

Here is how I sign the app on Xcode:

enter image description here enter image description here enter image description here enter image description here

Here is the code of the php page to send notifications:

    $ctx = stream_context_create();

    //stream_context_set_option($ctx, 'ssl', 'passphrase', 'development_pwd');
    //stream_context_set_option($ctx, 'ssl', 'local_cert', 'ck_development.pem');
    //$fp = stream_socket_client('ssl://gateway.sandbox.push.apple.com:2195', $err, $errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx); //test

    stream_context_set_option($ctx, 'ssl', 'passphrase', 'production_pwd');
    stream_context_set_option($ctx, 'ssl', 'local_cert', 'ck_production.pem');
    $fp = stream_socket_client('ssl://gateway.push.apple.com:2195', $err, $errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx); //production

    echo "<p>Connection Open</p>";
    if(!$fp){
        echo "<p>Failed to connect!<br />Error Number: " . $err . " <br />Code: " . $errstrn . "</p>";
        return;
    } else {
        echo "<p>Sending notification!</p>";    
    }

    $i = 0;

    foreach ($deviceToken as $dt) {
        $dt = str_replace(' ' , '' , $dt);
        $msg = chr(0) . pack('n',32) . pack('H*', $dt) . pack('n',strlen($payload)) . $payload;
        echo "<p>" . $i . " - Message sent: " . $payload . "<br />Token: ". $dt . "<br />***" . $msg . "***</p>";
        $result = fwrite($fp, $msg, strlen($msg));
        $i++;
        if (!$result)
            echo '<p>Message not delivered ' . PHP_EOL . '!</p>';
        else
            echo '<p>Message successfully delivered ' . PHP_EOL . '!</p>';
    }
    fclose($fp);
    echo "<p>Total Notifications Sent: " . $i . "</p>";
    echo "<p>Connection Closed!</p>";
}
?>

Conclusions: I have the Test App on my PC that receive APNS Push Notifications. I have the exactly same app released on App Store that not receive APNS Push Notifications.

I realy made everything in my power to fix this issue and read about thousand pages of forums, stackoverflow and Apple Documentations.

I'm willing to retribuite everyone of you who helps me find the solution to my issue!

Underpants answered 28/3, 2014 at 15:39 Comment(2)
For your info, the PHP script returns "Message successfully delivered" even if token is wrong or expired.Whitehot
Do I need to create two .csr files for Production & Development ?Palaver
C
18

The link you mentioned is Sandbox APNS link. Production APNS link is as per Apple documentation is:

You access the production environment at gateway.push.apple.com, outbound TCP port 2195.

Few things to verify:

  1. Your AppId is enabled for Distribution APNS.
  2. You have created Distribution APNS SSL Certificate and is installed on your build machine (for App Store submission).
  3. You have installed the SSL Certificate in step 2 on your server.
  4. You are not by mistake using Development APNS SSL Certificate.
Celia answered 29/3, 2014 at 2:23 Comment(7)
Actually I use the production link (gateway.push.apple.com), I made a mistake in my first post by pasting the development one.Underpants
1. It's enabled 2. Yes 3. Yes 4. No ...I tried the certificate with telnet and apple server responds successfully...Underpants
I added more informations about what I did could you please help me?Underpants
Hi @prelite, did you solve your problem. I face the same one and can not figure it out. Grateful if you can point out itGalengalena
Yes the problem was related to a bad generation of production certificates. Online there are a lot of tutorial that does not shows the right way to generate them.Underpants
Great for me at first step as a sniper! Thank you @gargawal !Hetero
@Underpants i'm seem to having the same problem. can you post any links that helped you solve this problem? And was the problem in provisioning profiles or just certificates? (If its provisioning profiles i have to resubmit to app strore)Consultative
S
14

Device token for Production and Sandbox are different for same device.

So try getting device token by using Adhoc or Distribution certificates and use the generated token on production, this worked for me.

Spotlight answered 4/6, 2014 at 10:36 Comment(0)
D
3

I Just came across the same problem. Push Notifications are arriving in Development Mode, not in Production. I also checked everything a few times and was sure that everything was fine.

But it wasn't. It was the very first step in the process. Creating the csr. I was sure I didn't have to create a csr file for Development and Production and ended up using the same csr file for both certificats. Didn't work...

Maybe someone in future does the same mistake und saves some time now.

Dilative answered 9/1, 2017 at 18:11 Comment(2)
Do you mean same csr file to create for both Production & Development is not correct? I should create two csr file, one for prd and another for dev?Palaver
I recreated the csr files followed by both development and production certificates. but no luck.Pralltriller
C
2

If you work with the Google Firebase Cloud Messaging means, Kindly check

  1. Make sure with your server team, your server is changed from development to production mode.

  2. Your production APN's certificate(convert into .p12 file) is uploaded on Google Firebase or not.

  3. Make sure the .p12 file is not exported with the key from the Keychain access. (like this)

  4. If it is uploaded already, then check the production APN's certificate's expiry date. Google FCM rejects the certificates before 2 months from the expiry date of the production APN's certificate.

Cerebro answered 6/4, 2020 at 14:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.