Redth / PushSharp

A server-side library for sending Push Notifications to iOS (iPhone/iPad APNS), Android (C2DM and GCM - Google Cloud Message), Windows Phone, Windows 8, Amazon, Blackberry, and (soon) FirefoxOS devices!
Other
4.39k stars 1.52k forks source link

Problem sending Push Notification iOS #834

Open napcat opened 7 years ago

napcat commented 7 years ago

What version of PushSharp are you using?

4.0.10

Describe your issue:

I can send push notifications to Android, but when I'm trying to send push notifications to ios, an error occurs:

Something went wrong in Comunications Worker: 
Method name -> PushNotifications.DispatchPushNotifications()
Message -> There is an error sending iOS push notifications.
Exception - > Specified argument was out of the range of valid values.
Parameter name: You are using a certificate created for connecting only to the Sandbox APNS server but have selected a different server environment to connect to.

I already created a certificate "Apple Push Notification service SSL (Sandbox & Production)" and also the individuals certificates "iOS App Development" and "App Store and Ad Hoc". In both cases I get the same error.

Is there any correct way to generate the certificate?

Can you point me the correct way, or is there any other bug or missing update?

Thank you, for your time.

ninjawithkillmoon commented 7 years ago

If we look at the code in this file: https://github.com/Redth/PushSharp/blob/master/PushSharp.Apple/ApnsConfiguration.cs, we can see that the error message you are receiving is generated because the certificate name has a certain word in it.

It is possible that the certificate file actually being used is wrong... but I have found that the certificate name (which is not something I think we have control over? - I think it's generated along with the certificate) can have some keywords in it that indicate it is a sandbox certificate, even though it is a production certificate.

You can disable the above check by passing false to the final parameter (validateIsApnsCertificate) when you call the ApnsConfiguration constructor. This might help :)

slthomason commented 6 years ago

@ninjawithkillmoon - this fixed it for me as well. Make sure to also check this out if you are having problems with the cert:

https://stackoverflow.com/questions/23329040/pushsharp-apns-production-the-credentials-supplied-to-the-package-were-not-reco