2

I am using PushSharp for Apple Push Notifications and it is working from console app and windows service on Windows 8 and Windows Server 2008R2, but the same code transferred to WebApi app on the same computers does not work. I've installed certificate and private key via mmc in Personal (the private key is available, granted permission for IIS_USRS) and Trusted Root Certificate Authorities. Code is kind of obvious, but just in case:

var push = PushBroker();
var appleCert = File.ReadAllBytes("C:\Users\Documents\Certificates\Push.p12");
push.RegisterAppleService(new PushSharp.Apple.ApplePushChannelSettings(false, appleCert, "pwd"));
PushSharp.Apple.AppleNotification notif = new PushSharp.Apple.AppleNotification()
    .ForDeviceToken("xxx")
    .WithAlert("Updated...")
    .WithBadge(1)
    .WithSound("default");
push.QueueNotification(notif);
//Wait for queue to finish
push.StopAllServices(true);

No errors/exceptions etc., its just the iPhone device does not get notifications when initiated in WebApi app.

Emad
  • 3,809
  • 3
  • 32
  • 44
Duke Ace
  • 177
  • 1
  • 12

2 Answers2

3

Have you checked all the event handles for errors? There's alot of them on the PushBroker instance where you can subscribe to intercept the error (if there is any).

Subscribe for: OnServiceException and OnNotificationFailed.

Check if the IIS|app|users|roles has all the privileges to access the web.

Vedran Mandić
  • 1,084
  • 11
  • 21
  • Looks like [http://stackoverflow.com/questions/23115394/pushsharp-apple-the-message-received-was-unexpected-or-badly-formatted] contains the answer. After updating PushSharp to 2.2.1 problem solved. – Duke Ace Nov 20 '14 at 04:28
  • Great, good news! In a few days I will be publishing a git repo with a complete PushSharp demo implementation on the server and clients, I'll post it here so you can check it later. – Vedran Mandić Nov 21 '14 at 14:52
1

When I had this error it was a certificate issue. Make sure you are using the correct certificate for production, since the first parameter is false in ApplePushChannelSettings, otherwise the message will not get delivered. Also step through the code and see if any errors are being generated but not logged.

Tony G.
  • 220
  • 1
  • 3
  • 11