уведомление с pushsharp

Я хочу реализовать уведомление в веб-приложении с помощью pushsharp.

Я нашел несколько примеров проектов на github для pushspharp, они работают.

пожалуйста, помогите мне начать разработку небольшого приложения для уведомлений с помощью pushsharp.

заранее спасибо


person user1924911    schedule 26.01.2013    source источник


Ответы (2)


открытый класс 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";
    }
}
person Mahesh    schedule 07.03.2013

У меня было приложение .net 3.5, и мне нужно было использовать PushSharp, поэтому в итоге я создал оболочку WebApi вокруг pushSharp, чтобы ее можно было использовать как простой RESTful API.

Я выложил код на GitHub, вдруг кому понадобится. PushSharp.Web

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

person Has AlTaiar    schedule 24.11.2013