关于推送通知 [英] Regarding Push notification

查看:68
本文介绍了关于推送通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好先生,



我是Likesh。我在mvc web api中创建了web服务。在这里我使用pushsharp dll向苹果设备发送推送通知。

但是通知不是在设备上发送而代码没有给出任何错误。

这里我的代码 -

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-

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;
        }
    }
}



谢谢

Likesh Puwar

likesh1989 @gmail.com


Thanks
Likesh Puwar
likesh1989@gmail.com

推荐答案

你好Likesh,



从文档中可以看出这个库很清楚不适合在ASP.NET中使用。作者建议创建一个服务并从中使用该库。如果你必须在ASP.NET中使用这个库,那么他建议需要在 Global.asax &中创建PushBroker作为 Singleton 。在 Application_End 中,您必须调用 StopAllServices 。另一个建议是要发送的消息需要保存在某些数据存储中,并从OnNotificationSent事件中删除。这将减少由于无法预料的应用程序池终止或重新启动而丢失的消息。



希望这可以帮助您解决问题。



问候,
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,


这篇关于关于推送通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆