iosasp.net-web-apiapple-push-notificationspushsharp

Apple Push Notifications from WebApi app


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.


Solution

  • 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.