0

I want to implement notification in web application with pushsharp.

I found some sample projects on github for pushspharp they are working.

please help me in getting start to develop small app on notifications with pushsharp.

thanks in advance

4

2 回答 2

1

公共类 PushNotificationService { 私有 PushService _pushService;

    public string MessageDetails { get; set; }
   // public RecipientDeliveryStatus MessageDeliveryStatus { get; set; }

    public PushNotificationService()
    {
        _pushService = new PushService();
        _pushService.Events.OnDeviceSubscriptionExpired += Events_OnDeviceSubscriptionExpired;
        _pushService.Events.OnDeviceSubscriptionIdChanged += Events_OnDeviceSubscriptionIdChanged;
        _pushService.Events.OnChannelException += Events_OnChannelException;
        _pushService.Events.OnNotificationSendFailure += Events_OnNotificationSendFailure;
        _pushService.Events.OnNotificationSent += Events_OnNotificationSent;
        _pushService.Events.OnChannelCreated += Events_OnChannelCreated;
        _pushService.Events.OnChannelDestroyed += Events_OnChannelDestroyed;

    }

    public void SendAppleNotification(string deviceToken, string message)
    {
        var appleCert = File.ReadAllBytes(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "../../../Resources/PushSharp.Apns.Sandbox.p12"));
        _pushService.StartApplePushService(new ApplePushChannelSettings(appleCert, "pushsharp"));
        _pushService.QueueNotification(NotificationFactory.Apple()
         .ForDeviceToken(deviceToken)
         .WithAlert(message)
         .WithSound("default")
         .WithBadge(7));
        _pushService.StopApplePushService();

    }


    public void SendAndroidNotification(string message, string deviceRegId)
    {
        _pushService.StartGoogleCloudMessagingPushService(new GcmPushChannelSettings("Config.AnrodidSenderId", "Config.AndroidAuthToken", "Config.AndroidApplicationId"));

        _pushService.QueueNotification(NotificationFactory.AndroidGcm()
                                           .ForDeviceRegistrationId(deviceRegId)
                                           .WithCollapseKey("NONE")
                                 .WithJson("{\"alert\":\"" + message + "\",\"badge\":\"7\"}"));
        _pushService.StopGoogleCloudMessagingPushService();
    }


    public void SendWindowsNotification()
    {
        _pushService.StartWindowsPhonePushService(new WindowsPhonePushChannelSettings());
        //Configure and start Windows Notifications
        _pushService.StartWindowsPushService(new WindowsPushChannelSettings("677AltusApps.PushSharpTest",
            "ms-app://s-1-15-2-397915024-884168245-3562497613-3307968140-4074292843-797285123-433377759", "ei5Lott1HEbbZBv2wGDTUsrCjU++Pj8Z"));

        //Fluent construction of a Windows Toast Notification
        _pushService.QueueNotification(NotificationFactory.Windows().Toast().AsToastText01("This is a test").ForChannelUri("YOUR_CHANNEL_URI_HERE"));
        _pushService.StopWindowsPhonePushService();
    }
    void Events_OnDeviceSubscriptionIdChanged(PlatformType platform, string oldDeviceInfo, string newDeviceInfo, Notification notification)
    {

      //  MessageDeliveryStatus = RecipientDeliveryStatus.Undeliverable;
        MessageDetails = "Device subscription id has changed";
    }

    void Events_OnNotificationSent(Notification notification)
    {

        //MessageDeliveryStatus = RecipientDeliveryStatus.Sent;
        MessageDetails = "Message Sent";
    }

    void Events_OnNotificationSendFailure(Notification notification, Exception notificationFailureException)
    {

        //MessageDeliveryStatus = RecipientDeliveryStatus.Undeliverable;
        MessageDetails = notificationFailureException.Message;
    }

    void Events_OnChannelException(Exception exception, PlatformType platformType, Notification notification)
    {

       // MessageDeliveryStatus = RecipientDeliveryStatus.Undeliverable;
        MessageDetails = exception.Message;
    }

    void Events_OnDeviceSubscriptionExpired(PlatformType platform, string deviceInfo, Notification notification)
    {

       // MessageDeliveryStatus = RecipientDeliveryStatus.Undeliverable;
        MessageDetails = "Device Subscription Expired";
    }

    void Events_OnChannelDestroyed(PlatformType platformType, int newChannelCount)
    {
       // MessageDeliveryStatus = RecipientDeliveryStatus.Undeliverable;
        MessageDetails = "Channel Descrtroyed";
    }

    void Events_OnChannelCreated(PlatformType platformType, int newChannelCount)
    {
        //MessageDeliveryStatus = RecipientDeliveryStatus.Undeliverable;
        MessageDetails = "Channel Created";
    }
}
于 2013-03-07T06:47:35.070 回答
1

我有一个 .net 3.5 应用程序,我需要使用PushSharp,所以我最终WebApi围绕 pushSharp 创建了一个包装器,以便它可以像一个简单的RESTfulapi 一样使用。

我已将代码放在 GitHub 上,以防有人需要。PushSharp.Web

https://github.com/has-taiar/PushSharp/tree/master/PushSharp.Web

于 2013-11-24T22:11:03.133 回答