Speaking of mobile applications, we all feel that mobile, of course, Java and object-c to do, what push ah, a variety of system calls Ah, it is not? If you know Qt,
You know what I'm talking about, and there's some truth.
Say what time
I. Current Android mobile message, notification push
1) Polling method: The application should periodically connect with the server and query whether there are new messages arriving, you must implement the communication with the server, such as Message Queuing. And you also have to consider the frequency of polling, if too slow can cause some message delay, if too fast, it will consume a lot of network bandwidth and battery.
2) SMS (Push) mode: On the Android platform, you can intercept the SMS message and parse the message content to understand the server's intentions and get its display content for processing. This is a good idea and I've seen applications that use this scenario. The benefit of this scenario is that full real-time operations can be achieved. But the problem is that the cost of the solution is relatively high, and we need to pay the cost to the mobile company. It is difficult to find a free short message sending gateway to implement this scenario.
3) Persistent connection (Push) mode: This solution can solve the performance problems caused by polling, but still consumes the battery of the phone. The push service for the iOS platform works well because each phone only maintains a connection to the server, and in fact C2DM works. But just now, there are a lot of shortcomings in this solution, that is, it is difficult for us to achieve a reliable service on the mobile phone, and currently can not be compared with the push function of the iOS platform.
4) Android Cloud to Device Messaging (C2DM) is a service that helps developers send data from a server to an Android application. The service provides a simple, lightweight mechanism that allows the server to notify the mobile application to communicate directly with the server to obtain application updates and user data from the server. The C2DM service is responsible for processing transactions such as Message Queuing and distributing these messages to applications running on the target device. About the specific use of C2DM, you can check the relevant information. 35) Use of third-party push services
Third-party platforms are commercially available and free of charge, and we can use them according to the implementation situation. On the domestic third-party platform, I feel that the current is more good is the aurora push. About Aurora Push is currently free and we can use it directly. For details, you can view its homepage: http://www.jpush.cn/index.jsp, which is no longer described in detail here.
With regard to MQTT, the recent emergence of a third-party solution based on MQTT in the country, Http://yunba.io, is known to have been created by the original Aurora push CTO, and interested friends can study it.
About the third-party platform abroad I have seen a few: http://www.push-notification.org/. Interested friends can check the relevant information. Using a third-party platform requires the use of someone else's server, which you understand.
6) Build your own push server
This is not an easy job, of course, according to their own needs to adopt the appropriate plan.
Based on the above points of the push scheme, combined with their own application of the actual situation, I chose a third-party push service, for the following points:
1. Third-party push service, including each mobile platform, for developers, can push notifications to a variety of platforms, cost savings
2. The data can be synchronized without any unnecessary work
3. Save development time.
Two. push for iOS and Mac platforms
1.Apple Push Notification Service, Apple server's own push services, has been integrated into the iOS system.
APNs provides two basic services: message push and feedback service.
Message push: Use streaming TCP sockets to send push notifications as binary data to APNs. Message push has two interfaces for the development and test sandbox, and each has its own address and port. Regardless of which interface you use, you need to use SSL certificates to establish a secure channel through TLS or SSL. The provider prepares the notification information and sends it to the APNS through this channel.
Note: sandbox:gateway.sandbox.push.apple.com:219
Product Interface: gateway.push.apple.com:2195
Feedback Service: You can get a send failure record for a program. The provider should use the feedback service to periodically check which devices are not receiving notifications, and do not need to send notifications repeatedly to these devices, reducing the burden on the push server.
Note: sandbox:feedback.push.apple.com:2196
Product Interface: feedback.sandbox.push.apple.com:2196
The APNs principle is as follows:
The first is the application registration message push.
iOS and APNs server to Devicetoken. The application accepts Devicetoken.
The application sends Devicetoken to the push server-side program (Provider).
The service-side program sends messages to the APNS service.
The APNs service sends messages to the iphone app.
Popular Description:
Apple Push order: The client obtains the token of the device, each device is unique, to the app side of the server, the app server will collect these devicetoken, and then need to push to connect the Apple server, the client's token pass through, of course, also have to pass the iOS push certificate, It is then delivered to the Apple server and pushed to the client by the Apple server itself.
Based on APNs service analysis:
The first stage: Push server (provider) to send the message, the logo of the purpose of the iphone packaging, sent to APNs;
Phase II: APNs in its own list of registered push service iphones, find the iphone with the corresponding logo and send the message to the iphone;
The third stage: The iphone sends the message to the appropriate application and follows the settings to eject the push notification.
Difficulties:
1. Need to write their own server, the collection of tokens sent to the APNS server, handed over to APNs to handle
2. To purchase and set up a push certificate, Apple developers need to spend $99 a year to pay for the development certificate and push Certificate Services
Based on the above considerations, if you want to save trouble, you can deliver a third-party push to help you save the service side of the trouble, of course, you can also handle the back end of the matter, I intend to deal with their own, the backend using the Nodejs+apns protocol to deal with
----------------------the above-mentioned push scheme and principle-------------------------------------------------------
Now, how do you apply it to the QT app?
1. For the full platform, third-party push is undoubtedly the best solution, saving development time
2. Combined with the various mobile platforms to handle the system APIs of each platform, and the third party sdk,android integrating the various systems using the Java JNI Call, iOS uses OBJECT-C integration, Windowphone not research, crossing self-supplement.
Third-party SDK entry for each system in QT platform
Android:
Pro file Join:
android{
LIBS + =-lgnustl_shared
QT + = Quick Androidextras
Android_package_source_dir = $ $PWD/android
SOURCES + = \
$ $PWD/yunba/notificationclient.cpp \
$ $PWD/yunba/simplecustomevent.cpp
Other_files + = \
$ $PWD/android/androidmanifest.xml \
$ $PWD/android/src/org/qtproject/dduijiao/pushtestwithjava.java \
$ $PWD/android/src/org/qtproject/dduijiao/extendsqtnative.java \
$ $PWD/android/libs/android-support-v4.jar \
$ $PWD/android/libs/yunba-sdk-release1.4.5.jar \
$ $PWD/android/src/org/qtproject/dduijiao/demoreceiver.java
HEADERS + = \
$ $PWD/yunba/notificationclient.h\
$ $PWD/yunba/simplecustomevent.h
}
iOS platform
Qmake_lflags + =-framework opengles
Qmake_lflags + =-framework Glkit
Qmake_lflags + =-framework cfnetwork
Qmake_lflags + =-framework Quartzcore
Qmake_lflags + =-framework Corevideo
Qmake_lflags + =-framework CoreAudio
Qmake_lflags + =-framework coreimage
Qmake_lflags + =-framework CoreMedia
Qmake_lflags + =-framework avfoundation
Qmake_lflags + =-framework Audiotoolbox
Qmake_lflags + =-framework coregraphics
Qmake_lflags + =-framework UIKit
Qmake_lflags + =-framework Security
Qmake_lflags + =-framework systemconfiguration
Ios:
LIBS + =-l$ $PWD/yunba/-lyunba
Includepath + = $ $PWD/yunba
Dependpath + = $ $PWD/yunba
Ios:
Pre_targetdeps + = $ $PWD/yunba/libyunba.a
The above platforms are joined by third-party push SDK, on how to use platform-related practices, refer to Foruok's blog
Recommend a few references
[APNs service under Nodejs] (https://github.com/toby20130333/node-apn/blob/master/examples/sending-to-multiple-devices.js)
[Cloud Buck Push] (http://yunba.io/)
If there is a problem contact QQ group (the bottom of the site)
The principle and application of message push service based on QT mobile application