Search code examples
c#ios.netpushsharp

PushSharp - ios - StopAllServices() hangs with no errors


I am trying to send a push notification to IOS device via PushSharp. For android, it works. For IOS, the call to StopAllServices() hangs forever, without calling any exception handlers.

Could the problem be that I was given a .pem certificate file, and pushsharp requires a .p12 file?

The code is the following:

var br = new PushBroker();
br.OnNotificationSent += br_OnNotificationSent;
br.OnNotificationFailed += br_OnNotificationFailed;
br.OnChannelException += br_OnChannelException;
br.OnServiceException += br_OnServiceException;
br.OnDeviceSubscriptionChanged += br_OnDeviceSubscriptionChanged;
br.OnDeviceSubscriptionExpired += br_OnDeviceSubscriptionExpired;
br.OnChannelCreated += br_OnChannelCreated;
br.OnChannelDestroyed += br_OnChannelDestroyed;

var appleCert = Resource1.ck; // this is a pem file, not a p12 file!!! could this be the problem?
var sandbox = true;
br.RegisterAppleService(new ApplePushChannelSettings(!sandbox, appleCert, "223684"));
// password given to me by ios developer

var deviceIds = new string[] { "09eddcb8b89494adf802a0caf97d5daaa789a53f52d8c544dbdcf39f2c0b619a" };

foreach (var did in deviceIds)
{
    br.QueueNotification(
         new AppleNotification()
               .ForDeviceToken(did)//the recipient device id
               .WithAlert("test: " + DateTime.Now.ToString())//the message
               .WithBadge(1)
               .WithSound("sound.caf"));
}
br.StopAllServices(waitForQueuesToFinish: true); // hangs forever, no callbacks are called

I am using PushSharp taken via Git, and compiled by myself with Visual Studio 2013, as of yesterday.

The hang happens both if the code is in a console application and in an asp.net application.

I am using the sandbox, because I was told to. If I use the production server, I get an exception telling me that the certificate is for the sandbox.

Thanks for any hint as to the cause of the freeze.


Solution

  • In the end it was a certificate problem. The .pem I was given is not accepted by PushSharp. Only when I was given a .p12 created with this guide

    https://code.google.com/p/apns-sharp/wiki/HowToCreatePKCS12Certificate

    , the problem was solved.

    However, PushSharp should have raised an exception instead of hanging.