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