PushSharp APNS Service Stop working after windows shutdown

放肆的年华 提交于 2019-12-13 02:31:53

问题


I can send notifications to my iPhone device succeffully using Push Sharp via sandbox APNS server but I am having a problem.

I have generated .cer and .p12 files and then installed them on my windows 8 development machine successfully.

I used this tutorial to install the certificates on my windows 8 machine.

Yesterday things were working fine and I was sending the notification successfully. I shutdown my system and then next day when I try to run the code I was getting following exception:

the message was unexpected or badly formatted pushsharp

I tried different solution available on Google but nothing helped. Then I delete the certificates from my machine and then re-install them and things started to work again.

In order to make the service fool proof I shutdown the system to check if notification sending fails or not, and yes it fail again with the same exception.

I again deleted the certificates and re-install them to correct the issue. I do not know whats the actuall problem? what makes PUSHSharp to stop sending notification after shutdown.

Note: Windows firwall is disabled. Any idea?


回答1:


I have been working with PushSharp for the past few weeks and have not had this problem. My environment is Windows 7 however. After you've created the appropriate Push Notification Certificate in iPhone Developer Program Portal you should have downloaded a file named something like apn_developer_identity.cer. If you have not done so already, you should open/import this file into Keychain, into your login section.

Finally, if you filter Keychain to show your login container's Certificates, you should see your Certificate listed. Expand the certificate, and there should be a Key underneath/attached to it.

Right Click or Ctrl+Click on the appropriate Certificate and choose Export. Keychain will ask you to choose a password to export to. Pick one and remember it. You should end up with a .p12 file. You will need this file and the password you picked to use the Notification and Feedback Libraries here.

OpenSSL

Here is how to create a PKCS12 format file using open ssl, you will need your developer private key (which can be exported from the keychain) and the CertificateSigningRequest??.certSigningRequest

  1. Convert apn_developer_identity.cer (der format) to pem: openssl x509 -in apn_developer_identity.cer -inform DER -out apn_developer_identity.pem -outform PEM}

  2. Next, Convert p12 private key to pem (requires the input of a minimum 4 char password): openssl pkcs12 -nocerts -out private_dev_key.pem -in private_dev_key.p12

  3. (Optional): If you want to remove password from the private key: openssl rsa -out private_key_noenc.pem -in private_key.pem

  4. Take the certificate and the key (with or without password) and create a PKCS#12 format file: openssl pkcs12 -export -in apn_developer_identity.pem -inkey private_key_noenc.pem -certfile CertificateSigningRequest??.certSigningRequest -name "apn_developer_identity" -out apn_developer_identity.p12

Once you generate the p12 file using these steps you will not really need to snap it to your console. You will just need to make changes in your code as follows:

 var appleCert = File.ReadAllBytes("C:/Certificate/aps_dev_identity.p12");

Hope this helps.




回答2:


I have been working on MOON APNS since 2012 and it's working fine but from last few days i am getting below error message

Error Message : System.Security.Authentication.AuthenticationException: A Call to SSPI failed, see inner exception.

System.ComponentModel.Win32Exception: The message received was unexpected or badly formatted

Solution : in PushNotification.cs file replace

_apnsStream.AuthenticateAsClient(host, certificates, System.Security.Authentication.SslProtocols.Ssl3, false);

with

_apnsStream.AuthenticateAsClient(host, certificates, System.Security.Authentication.SslProtocols.Tls, false);

As, I didn't find any confirmation from apple side but from github.com I found solution for this and it's work for us.

It's seems that apple depricate "unsafer" protocol SSL.




回答3:


Check first if you can do the notifications with C# code like this one first, then worry about the installation. I had the same message when I was trying to execute the code, I didn't care about installation, and solved it by making sure that I use a certificate of type .p12 and not .pem and to make sure that the .p12 had a password. I can now send notifications to my iPhone from a console C# app in my pc.



来源:https://stackoverflow.com/questions/20265853/pushsharp-apns-service-stop-working-after-windows-shutdown

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!