Search code examples
c#.netpushsharp

error while sending notification using PushSharp 2.2.1.0 iOS


I am using PushSharp version 2.2.1.0, and referencing "PushSharp.Core" and "PushSharp.Apple" libraries for iOS. I have removed all restrictions from firewall for the same because it was concerning some security issues.

I Have exported certificate from device using key or without key. While sending notification my code is stucking in stopAllServices() method of PushBroker class.And in some cases where i am setting SkipSsl=true of ApplePushChannelSettings(I am not using ssl), I am getting error "Credentials supplied to the package were not recognized" which was also issued here a long time back :https://code.google.com/p/apns-sharp/issues/detail?id=3. after reaching at this method my program getting hanged. here is my code :

 //Create our push services broker
        var push = new PushBroker();

        //Wire up the events for all the services that the broker registers
        push.OnNotificationSent += NotificationSent;
        push.OnChannelException += ChannelException;
        push.OnServiceException += ServiceException;
        push.OnNotificationFailed += NotificationFailed;
        push.OnDeviceSubscriptionExpired += DeviceSubscriptionExpired;
        push.OnDeviceSubscriptionChanged += DeviceSubscriptionChanged;
        push.OnChannelCreated += ChannelCreated;
        push.OnChannelDestroyed += ChannelDestroyed;


        var appleCert = File.ReadAllBytes(FileHelper.CERTIFICATEFILE);
        X509Certificate2 Cert = new X509Certificate2(appleCert, FileHelper.PASSWORD, X509KeyStorageFlags.MachineKeySet);
 push.RegisterAppleService(new ApplePushChannelSettings(false, appleCert, FileHelper.PASSWORD)); 
   push.QueueNotification(new AppleNotification()
                                       .ForDeviceToken(DeviceID.ToUpper()/*my device id*/)
                                       .WithAlert("my message")
                                       .WithSound("default")
                                       .WithBadge(1)
                                       .WithCustomItem("status", new object[] { "sucess") })
                                       .WithCustomItem("identifier", new object[] { "1"}));
push.StopAllServices();

I have also tried using certificate without password. Its firing ChannelCreated and after this its reaching to ServiceException.


Solution

  • I found it working , when using certificate without password.