The implementation of the. NET Platform Push iOS messages _ practical Tips

Source: Internet
Author: User

The example in this article describes the implementation of the. NET Platform for pushing iOS messages. Share to everyone for your reference.

The following steps are implemented:

1. Allow messages to be pushed to customers in iOS applications

2, need to have Apple's certificate and password (how to obtain, online search, need to pay the fee)

3, the iphone phone, installed the iOS application

4. NET project Reference Pushsharp.apple.dll,pushsharp.core.dll (these two files are searched on the Internet, has the source code)

5, start writing code, define the global object Pushbroker pusher = new Pushbroker ();

6. Registration Method:

Copy Code code as follows:
protected void startApp ()
{
Pusher. Registerappleservice (New Applepushchannelsettings (File.readallbytes (Certificatepath), CertificatePassword));
Pusher. Ondevicesubscriptionchanged + = pusher_ondevicesubscriptionchanged;
Pusher. Ondevicesubscriptionexpired + = pusher_ondevicesubscriptionexpired;
Pusher. Onnotificationsent + = pusher_onnotificationsent;
Pusher. onnotificationfailed + = pusher_onnotificationfailed;

}
static void Pusher_onnotificationfailed (object sender, inotification notification, Exception error)
{
var n = (applenotification) notification;
Error. Message ... To get information about push errors
Log.error ("Push error message", error);
}

static void Pusher_onnotificationsent (object sender, Inotification notification)
{
After the message was pushed successfully
var n = (applenotification) notification;
N.payload.alert.body get message content for push ...
Log.error ("Push content" +n.payload.alert.body);
}

static void Pusher_ondevicesubscriptionexpired (object sender, String Expiredsubscriptionid, DateTime EXPIRATIONDATEUTC, inotification notification)
{
Remove expired Expiredsubscriptionid from the database
}

static void Pusher_ondevicesubscriptionchanged (object sender, String Oldsubscriptionid, String Newsubscriptionid, Inotification notification)
{
Update the Oldsubscriptionid in the database to Newsubscriptionid
}

There are two parameters in the StartApp () method:

Certificatepath: Path to Certificate
Certificatepassword: Password

7, Push the code:

Copy Code code as follows:
Pusher. Queuenotification (New Applenotification (). Fordevicetoken (Tokenid). Withalert ("Push content"). Withbadge (1). Withsound ("Default"))//Tokenid from the database or other places to get the device, one for each iphone Tokenid

8, ready after these can be tested, I personally tested through, if there is any do not understand where to welcome the message exchange!

9, if you want to push on Android devices, the project to introduce PushSharp.Android.dll, code words later will be updated for everyone, please pay attention!

10, complete example code click here to download the site.

I hope this article will help you with your. NET programming.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.