Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

{error, closed} in apns:connect and general cluelessness on my behalf #103

Closed
peffis opened this issue Apr 28, 2016 · 6 comments
Closed
Labels

Comments

@peffis
Copy link

peffis commented Apr 28, 2016

Hi,

When I do apns:connect I get an {error, closed} back in return. What is the recommended way of finding out why this happens? I do not see any logs anywhere and I see nothing on the console.

Also, I suspect this is due to some problems with my certificates - an area which I am in general a bit clueless about at the moment and I find it a bit complex. Is there some documentation on how the cert_file and key_file used in apns4erl relates to the Apple certificates (the developer certificate and the push notification certificates) or any good documentation on how to set it up? I have for instance both an aps.cer and aps_development.cer and I understand I should generate a .pem file to input to apns4erl. Which .p12 file should I combine with the .cer to generate the cert_file .pem and which files should I combine to generate the key_file .pem? In your example sys.config you leave the key_file as "undefined" but I really need to specify a keyfile don't I?

/Stefan

@manuel-rubio
Copy link
Contributor

Yes, usually when the {error, closed} is immediately that should be because the certificate is not valid for Apple. Ensure the certificate is in the correct format (you should see only one BEGIN CERTIFICATE in the certificate file), and the key file is correct and if it's protected with password, you also have the password in the configuration.

Ensure also you are connecting to the correct domain, depending on if it's the test env or the prod env. And finally even one check for dates with openssl command:

openssl x509 -in file.pem -noout -dates

@peffis
Copy link
Author

peffis commented Apr 29, 2016

Yes, it was the certificate. I regenerated the files and now it connects. Now it seems to connect at least although I don't get the message through :)

Two questions:

  1. What does "Feedback server disconnected. Waiting 18000000 millis to connect again..." mean? I get this when it starts up. Is this because the app is only in development/TestFlight mode and there is no Feedback to be done by the Feedback server?

  2. When I send a message now with "apns:send_message(my_connection_name, MyDeviceToken, "Hello")." I get first a
    Sending msg <<"}²$/">> (expires on 1461998386)

and then...
Error trying to inform error (invalid_token) msg <<"}²$/">>: undef

Does this mean that Apple thinks that the device token is invalid? The token IS the one reported from the phone - a 64 character string of hex characters. Or does it mean that something else is wrong? The "undef" in the error message seems to indicate some internal problem somewhere.

@peffis
Copy link
Author

peffis commented Apr 29, 2016

The "undef" part was because of my own fault (I had not started lager which I used in the error callback function). Now it says:

APNS disconnected08:52:54.298 [error] error: <<128,198,67,89>> - invalid_token

So the device token seems to be bad somehow, right? I wonder why that is...

@peffis
Copy link
Author

peffis commented Apr 29, 2016

...ok, so if anyone finds this because they were having similar problems, I will document here that the problem with the invalid token was because the app was signed with a different key (the distribution key) and my push service was communicating with the development sandbox. I rebuilt the app with the right key and then got a different device token...a token that worked.

I will stop showing my ignorance when it comes to all the certificate/profile issues on this thread now. I promise :) (although, to be fair, I do think apple has made it quite messy, and xcode is not the reliable friend for this always). Sorry to bother you guys. Thanks for the code.

@manuel-rubio
Copy link
Contributor

don't worry peffis... about this message:

Feedback server disconnected. Waiting 18000000 millis to connect again...

That's because APNS has the possibility to give you feedback about the devices uninstalled. This library opens that feedback channel every 18000000 millis (you can change the frequency in the configuration), retrieves information if there are something and calls the callback you provide it for every chunk of information.

@ferigis ferigis added the 1.x label Feb 13, 2017
@ferigis
Copy link
Member

ferigis commented Feb 13, 2017

I think we can close that ticket

@ferigis ferigis closed this as completed Feb 13, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants