Remote push
is to push the message from the remote server to the client's notification, of course, need to network.
Remote Push service APNs (Apple push notificationservices)
Why do I need remote push notifications?
The limitation of traditional data acquisition is that users cannot communicate with the app's server and get the latest data content from the server as long as the user closes the app.
Remote push notifications can solve this problem, whether users open or close the app, as long as the Internet, you can receive the server push remote notification.
Let's start with the Internet connection.
HTTP protocol: is a short connection, a request for a response is over. A typical network request.
TCP/IP protocol: three-time handshake connection, as long as the server or client does not actively disconnect, remain connected. Probably QQ chat is this kind of agreement.
Push, we start from QQ chat.
A user and B user chat:
1.A and B users are online at the same time, keep connected with the server: "A sends a message to B: Is it?" , b reply: in the. "We analyze the process.
->a will the message "in?" "Sent to the QQ server, at this time because B and the server also remain connected, so the server sends the message to B, the same B's reply also reverse transmission is established.
2.A sends a message to B, but B is not in line.
In this case, the server cannot send a message to B. How do we get a message when our phone is not on the line?
Then we have to take out the artifact and push it remotely. Remote push is implemented via Apple's APNs server. As long as your Apple device is networked, your device will remain in a long-connected state with Apple's APNs server.
Then we can think of, when a message is sent to the server, the way the server sends the message to the APNS server can be implemented to send the message to B, how exactly is it implemented? We look down:
1. A and B installed QQ client, login their QQ number, A and B will own QQ number + Apple device Devicetoken sent to QQ server, QQ server will this set of data in its own database.
Get the Devicetoken method, in APPDELEGATE.M:
-(void) Application: (UIApplication *) application Didregisterforremotenotificationswithdevicetoken: (NSData *) Devicetoken {}
2.A will the message "in?" "When sent to B, the server found that B is not in line, at this time, the server from the database to find B corresponding to the Devicetoken, will B's devicetoken+ message" in? "Sent to the APNs server.
After the 3.APNs server receives the message, find B corresponding to the Devicetoken, will the message "in?" "Device sent to B.
Then there is a question, APNs server will send the message to the device B, how to know is QQ client?
In fact, this thing is Devicetoken included, when you get Devicetoken, Apple secretly will device Udid and app and bundle identifier sent to Apple server, Apple server returned to you devicetoken, Therefore, the QQ server sends the message +b Devicetoken to the Apple APNs server, Apple already knew which client is.
----End
Copyright NOTICE: This article is the original blogger article, reproduced please indicate the source: http://blog.csdn.net/zhangwenhai001
iOS Remote push principle