Remote push
is a notification that pushes a message from a remote server to the client. Of course, networking is required.
Remote Push service APNs (Apple push notificationservices)
Why do I need to send a remote push notification?
The limitation of traditional access to data is that the user closes the app only. You won't be able to communicate with the app's server. Unable to get the latest data content from the server
Remote push notifications can solve the problem, whether the user opens or closes the app, only to be networked, 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 handshake connection, only the server or client is not actively disconnected. Keep the connection. Probably QQ chat is such an agreement.
Push, we start from QQ chat.
A user and B user chat:
1.A and B users are online at the same time, and remain connected to 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 Qqserver, because B is also connected to server, so the server sends the message to B, and the same B reply is reversed."
2.A sends a message to B. But B is not on the 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 achieved through Apple's apnsserver. Just to get your Apple device connected, your device stays in a long-connected state with Apple's apnsserver.
Then we'll be able to think. When a message is sent to the server, the way the server sends the message to Apnsserver can be implemented by sending the message to B, how is it implemented in detail? We look down:
1. A and B install the qqclient. When you log in to your QQ number. A and B send their QQ number + Apple device Devicetoken to Qqserver,qqserver to save this set of data in their own database.
Gets the Devicetoken method. In the APPDELEGATE.M:
-(void) Application: (UIApplication *) application Didregisterforremotenotificationswithdevicetoken: (NSData *) Devicetoken {}
2.A will the message "in?" "When sending to B, Server discovers B is not in line, at this time, the server looks for b corresponding devicetoken from the database, will B's devicetoken+ message" in? "Sent to Apnsserver.
3.APNsserver after receiving the message, find B corresponding Devicetoken, will the message "in?" "Device sent to B.
Then another question. Apnsserver sends the message to device B. How do you know it's qqclient?
In fact, plainly. This thing is Devicetoken included, when you get Devicetoken, Apple secretly sent the device Udid and app and bundle identifier to Apple server. Apple server has returned to you devicetoken. So qqserver the message +b's Devicetoken to Apple's apnsserver, Apple already knows which client it is.
----End
iOS Remote push principle