. NET Platform Push iOS messages

Source: Internet
Author: User

Allow messages to be pushed to customers in the 1,ios application

2, need to have an Apple certificate and password (how to get, online search, need to pay)

3,iphone mobile phone, which installs the iOS app

4,.net Project References Pushsharp.apple.dll,pushsharp.core.dll (these two files are searched on the Internet, have the source code)

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

6, registration method

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) {V            Ar n = (applenotification) notification; Error. Message ...        Get information about push error log.error ("Push error message", error);            } static void Pusher_onnotificationsent (object sender, Inotification notification) {///after successful message push            var n = (applenotification) notification;            N.payload.alert.body get push message content ... Log.error ("Push content" +n.paylOad.        Alert.body); } static void Pusher_ondevicesubscriptionexpired (object sender, String expiredsubscriptionid, DateTime Expirationda TEUTC, inotification Notification) {//delete expired Expiredsubscriptionid} from database static void Pushe R_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 the certificate
Certificatepassword: Password 7, push code

Pusher. Queuenotification (New Applenotification (). Fordevicetoken (Tokenid). Withalert ("Push content"). Withbadge (1). Withsound ("Default"));//Get the Tokenid of the device from a database or other place, one tokenid per iphone

8, ready after these can be tested, I personally test through, if there is what do not understand the place message communication, hope to everyone has help!

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

10, Source Address: Http://pan.baidu.com/s/1pJoD8IR

. NET Platform Push iOS messages

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.