Overview

There are two common ways to use this library, you can either use the high level ApnsNotificationChannel and FeedbackService classes to send notifications or, if you need to customize the threading model you can use the lower level classes to build your own solution.

The majority of people will want to use the high level classes:

Sending a basic notification

The following example sends a simple notification message using the ApnsNotificationChannel class. This example shows the following concepts:
  1. Open your APNS certificate using the X509Certificate class
  2. Open the Notification Channel, supplying the X509Certificate.
  3. Specify the device to send the notification to using the DeviceToken class.
  4. Specify the body of the notifucation using the NotificationPayload class.
  5. Construct a ApnsNotification object to transmit.
  6. Use the Channel to send the notification.
  7. Close the Channel, this returns the status of all of the notification messages sent as a dictionary. There will be a key in the dictionary for every notification sent, and a SendResult that contains the status of the message.

X509Certificate certificate = new X509Certificate(@".\MyApnsCertificate.pvk");
using (ApnsNotificationChannel channel = ApnsNotificationChannel.OpenNotificationChannel(certificate, true))
{
    DeviceToken deviceToken = "1234";
    NotificationPayload payload = new NotificationPayload("Alert from apns.net");
    ApnsNotification notification = new ApnsNotification(deviceToken, payload);
    channel.SendNotification(notification);

    var results = channel.Close();
}

Checking for Feedback

The following example sends a simple notification message using the FeedbackService class. This example shows the following concepts:
  1. Open your APNS certificate using the X509Certificate class.
  2. Open the Feedback Service, supplying the X509Certificate.
  3. Ask for feedback using the service.

X509Certificate certificate = new X509Certificate(@".\MyApnsCertificate.pvk");
using(FeedbackService feedback = FeedbackService.OpenFeedbackChannel(certificate, false))
{
    var feedbackResults = feedback.CheckForFeedback();
}


Detailed documentation of the lower level classes can be found here

Last edited Jul 14, 2011 at 1:56 PM by owenssam, version 12

Comments

No comments yet.