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
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
public class PushNotificationService { private 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";
}
}
I had a .net 3.5 application and I needed to use PushSharp
, so I ended up creating a WebApi
wrapper around pushSharp so that it can be consumed just as a simple RESTful
api.
I have put the code on GitHub in case anybody needs it. PushSharp.Web
https://github.com/has-taiar/PushSharp/tree/master/PushSharp.Web