Click here to Skip to main content
15,939,736 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Sir,

I am Likesh . I have created web service in mvc web api. and here i am sending push notification to apple device using pushsharp dll.
But notification is not sending on device and code is not giving any error .
Here my code-
C#
public void SendPush(string deviceToken, string message, string baseurl)
{
    if (!string.IsNullOrEmpty(deviceToken))
    {
        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;
        try
        {
            string ss = HostingEnvironment.MapPath(@"~\Resources\Certificates2.p12");
            var appleCert = File.ReadAllBytes(ss);
            push.RegisterAppleService(new ApplePushChannelSettings(false, appleCert, "123"));
            push.QueueNotification(new AppleNotification()
            .ForDeviceToken(deviceToken)//the recipient device id
            .WithAlert(message)//the message
            .WithBadge(5)
            .WithSound("snap audio alert.mp3")
                // .WithSound("default")
            );
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
}

Thanks
Likesh Puwar
likesh1989@gmail.com
Posted
Updated 27-Nov-14 22:24pm
v2

1 solution

Hello Likesh,

From the documentation it's very clear that this library is not best suitable for use in ASP.NET. The author is suggesting to create a service and use this library from it. If you must use this library in ASP.NET then he is suggesting that PushBroker needs to get created as Singleton in Global.asax & in Application_End you must call StopAllServices. Another recommendation is that the messages to be sent needs to be persisted in some data store and be removed from from the OnNotificationSent event. This will mitigate losing messages due to unforeseen App Pool terminations or restarts.

Hope this helps you solve your problem.

Regards,
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900