-
Notifications
You must be signed in to change notification settings - Fork 108
Sending A Simple Notification
smoak edited this page Aug 2, 2011
·
1 revision
In order to send a notification you'll need to know the device token to send to. You'll also need to create a certificate for use with sending notifications.
Now that you have that information you can begin using the library. We need to get the full path to the certificate you created earlier:
string p12FileName = "C:\apple_ios_certificate.p12"; // change this to reflect your own certificate
string p12Password = ""; // change this
Create a new instance of the NotificationService class:
bool sandBox = true;
int numConnections = 1; // you can change the number of connections here
var notificationService = new NotificationService(sandBox, p12FileName, p12Password, numConnections);
Now we can create our notification to send:
var deviceToken = ""; // put in your device token here
var notification = new Notification(deviceToken);
notification.Payload.Alert.Body = "Some message";
notification.Payload.Sound = "beep.wav";
notification.Payload.Badge = 1;
if (notificationService.QueueNotification(notification)) {
// queued the notification
} else {
// failed to queue
}
The above will queue the notification to be sent. Now we just need to do some cleanup:
// This ensures any queued notifications get sent befor the connections are closed
notificationService.Close();
notificationService.Dispose();
That's it for creating a simple notification.
string p12FileName = "C:\apple_ios_certificate.p12"; // change this to reflect your own certificate
string p12Password = ""; // change this
bool sandBox = true;
int numConnections = 1; // you can change the number of connections here
var notificationService = new NotificationService(sandBox, p12FileName, p12Password, numConnections);
var deviceToken = ""; // put in your device token here
var notification = new Notification(deviceToken);
notification.Payload.Alert.Body = "Some message";
notification.Payload.Sound = "beep.wav";
notification.Payload.Badge = 1;
if (notificationService.QueueNotification(notification)) {
// queued the notification
} else {
// failed to queue
}
// This ensures any queued notifications get sent befor the connections are closed
notificationService.Close();
notificationService.Dispose();