. NET push notifications to APNS apple,. netapns Apple notifications

Source: Internet
Author: User

. NET push notifications to APNS apple,. netapns Apple notifications
1. Apns introduction:

Apns is an apple push notification service.

Ii. Principles:

APNs performs physical connection authentication and device Token Authentication (in short, Apple's server checks the certificate on the device to determine it as an Apple device );
Then, the server information is received and saved in APNs, and APNs searches for the IOS device from the list registered in it (the device can be iPhone, iPad, iPod Touch, version is iOS3.0 or later) and the information is sent to the device;

Establish a connection between Provider and APNS, and establish a connection between APNS and Device. Both connections are encrypted and use the TLS method. The encrypted certificate must be generated, there are two types of certificates: "Developer certificate". apps using developer certificates can be published on the APPSTORE, and "enterprise certificate ", apps that use enterprise certificates can only be sent to the internal market of the enterprise and cannot be sent to the APPSTORE.

3. Use the. NET open-source class library PushSharp to push messages to Apple APNS.

Download PushSharp open-source project compilation https://github.com/Redth/PushSharp

After compilation, you need to use the three assembly library files Newtonsoft. Json. dll, PushSharp. Apple. dll, and PushSharp. Core. dll for APNS push.

Then, the ios client needs to provide the. p12 Certificate file and the encrypted password of the Certificate file.

After you have prepared these items, create a new console program to reference the above library file, copy the certificate to the root directory, change the attributes, and output the certificate to the copy directory to always copy

Class Program {static ApnsConfiguration config; static ApnsServiceBroker apnsBroker; static void Main (string [] args) {config = new ApnsConfiguration (ApnsConfiguration. apnsServerEnvironment. sandbox, "certificate. p12 "," certificate encryption password "); apnsBroker = new ApnsServiceBroker (config); // push exception apnsBroker. onicationicationfailed + = (notification, aggresponex) => {aggresponex. handle (ex => {// identify exceptions and diagnose if (ex is apnsica TionException) {var notificationException = (ApnsNotificationException) ex; // handle failed notifications var apnsNotification = icationicationexception. notification; var statusCode = icationicationexception. errorStatusCode; Console. writeLine ("Apple Notification Failed: ID = {apnsNotification. identifier}, Code = {statusCode} "+ notification. deviceToken);} else {// internal exception Console. writeLine ("Apple Notification Failed for some u Nknown reason: {ex. innerException} "+ notification. deviceToken) ;}// mark as processing return true ;}) ;}; // push successful apnsBroker. onNotificationSucceeded + = (notification) => {Console. writeLine ("Apple Notification Sent! "+ Notification. deviceToken) ;}; // start the proxy apnsBroker. start () ;}/// <summary> /// push the message // </summary> public static void SendMsg () {List <string> MY_DEVICE_TOKENS = new List <string> () {"success", "success"}; foreach (var deviceToken in MY_DEVICE_TOKENS) {// The queue sends a notification to apnsBroker. queueNotification (new ApnsNotification {DeviceToken = deviceToken, // The deviceToken here is obtained by the ios end and transmitted to the database for unified record management. Only valid tokens can ensure successful push Payload = JObject. parse ("{\" aps \ ": {\" sound \ ": \" default \ ", \" badge \ ": \" 1 \", \ "alert \": \ "This Is A Test message pushed by group advertising messages \" }}");} // stop the proxy apnsBroker. stop (); Console. read ();}}

The above implementation. NET to APNS Apple message push notification function, this is just an example, in the actual project development, need to communicate with the IOS end, for example, when a user downloads a token from an IOS application to a database, how to manage it, how to push messages to all users and individual users, and how to avoid repeated message pushing, it can be developed as a proxy service to implement corresponding interfaces for the push party to call, similar to the laser push interface to achieve unified management.

Messages are pushed to Android devices. Unlike Apple's APNS, Android does not have a unified channel to manage device tokens and some Android mobile phone system developers, for example, Xiaomi and Huawei have their own unified channels for push management, similar to Apple's APNS push service. However, if you want your applications to receive push messages on all Android devices, if you do not use third-party push to develop a push service by yourself, you need your push proxy service to maintain a long link with the device. Managing these links is a headache, for example, a Wi-Fi LAN or a 234G network may cause a disconnection and reconnection, and how to use the least-consumed traffic to maintain a persistent connection between the device and the push proxy is a challenge. After channel Establishment and Management, messages are pushed and managed.

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.