0

pushsharp を使用して Web アプリケーションに通知を実装したいと考えています。

github で、動作中の pushspharp のサンプル プロジェクトをいくつか見つけました。

pushsharp を使用して、通知に関する小さなアプリの開発を開始するのを手伝ってください。

前もって感謝します

4

2 に答える 2

1

私は .net 3.5 アプリケーションを持っていて、.net を使用する必要があったため、単純な API として使用できるように、pushSharp のラッパーPushSharpを作成することになりました。WebApiRESTful

誰かがそれを必要とする場合に備えて、コードを GitHub に置きました。PushSharp.Web

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

于 2013-11-24T22:11:03.133 に答える
1

public class 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 に答える