In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
Editor to share with you the example analysis of iOS APNs, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
Preface:
Because of the functional needs of App, I have been investigating Apple's APNs push recently. At first, I felt super troublesome, but now I still feel more easy. "the difficult will not, the meeting will not be difficult". After stepping through so many pits, I finally know how to do it. I don't come out to complain (pretend X) to feel sorry for myself, 23333.
First to give you a small welfare, because APNs can only be tested on the real machine, the simulator can not be used, if there is no iPhone students, you can take this opportunity to apply to the boss to apply for an iPhone, can apply for it depends on the ability, I just do not have iPhone, and then use this way to let the company match the iPhone.
Then, you need to write the service code. When you test and send APNs messages, you need to write the server code to send messages to the Apple server. As a pure iOS developer, I know everything about the server code. Fortunately, many third parties on the Internet provide this function. Because our company uses a push, we directly use the function provided by a push. It's nice that I don't need to write the server code.
Preparatory work:
1. Apple development license certificate, which is divided into development certificate (iOS App Development), production certificate (App Store and Ad Hoc), etc. Later, I use the development certificate for testing.
2. Register "AppIDs" on the Apple developer website. I use "com.crazywolf.yewan" and check "Push Notifications".
3, the real machine (come on, iPhone is waiting for you), need to be added to the development license equipment.
4 、 Provisioning
Profiles file, sub -: development use (iOS App Development), production use (App Store, Ad Hoc), etc., I use "Development" later.
5. Apple APNs push certificate, such as development environment certificate (Development), production environment certificate (Production), etc. Similarly, using "Development", note that using a push platform APNs push needs to upload the push certificate. Here I submit the exported development environment certificate to a push platform. About certificate production and export, you can see a push APNs configuration technical document (docs.getui.com/mobile/ios/ … ).
6. Xcode8.2 (different versions are a little different when configured). The minimum supported version is iOS 8.0.
One: register APNs and obtain DeviceToken
1. Create a new project or modify an old project, and configure the project
2. Register APNs and obtain DeviceToken
3. Use a push to test the DeviceToken.
Is it very simple, so you can get APNs push messages and have a sense of success? but when I started to get DeviceToken, I kept reporting ("ErrorDomain = NSCocoaErrorDomain Code=3000").
"could not find the authorization string of the" aps-environment "of the application" UserInfo= {NSLocalizedDescription= could not find the authorization string of the "aps-environment" of the application. It was said on the Internet that the certificate was not properly configured, but I reconfigured the certificate many times. Later, I asked the technical support of a push to know that the above version of Xcode8 needs to open "TARGETS -".
"Capabilities-Push Notifications", which is also written in the integration document of a tweet, is too careless.
4. APNs environmental problems
Be careful to keep the push APNs environment consistent with your App push environment, because someone will often get the certificate environment wrong and the push will not be received.
1) use Xcode to run directly to the mobile phone, and you can run it according to "TARGETS-> General".
-> Signing "Provisioning Profile" and "Signing Certificate" to confirm. For example, the following figure:
To share, I have a habit of naming "Provisioning Profile" files with "Dev:" (development environment), "In House:" (enterprise package environment), "XC Ad Hoc:" (distribution environment), "XC:" (App Store), the last three of which are production environments.
2) if you pack an ipa package and install it on iPhone, you may forget the configuration when you pack it or someone else will send your package, so you can't know the environment of APNs? My method a long time ago was to get the DeviceToken of App and push it using both the development and production environment APNs certificates to see which one could be pushed to. Later, it was discovered that there was another way to parse the ipa package:
1) first extract the ipa package, find the .app file, and display the contents of the package.
2) find the .Mobilization file and use "Atom" to open the .Mobilization file
3) look for "aps-environment" and see that the key value of "aps-environment" corresponds to value. "development" represents the development environment and "production" represents the production environment. As shown below:
Second: officially push APNs, push the information we need.
1. Integrate a push SDK
How to configure a tweet, you can see "docs.getui.com/mobile/ios/... /". Run the "clientId" to get a tweet after the configuration is successful.
2. Use the "transparent message" on a Twitter website to send it.
In this way, you can push the custom message content to iPhone, where all the functions of APNs have been completed, and then we will look at the specific requirements. Send the server integration part of a push to your server developer to "code" it. If you have any problems, let them contact the technical support of a push, 2333.
3. APNs message statistics
The latest version 1.5.3 iOS SDK adds "iOS10 APNs display Statistics" feature, which uses the new features of iOS10 and requires the addition of NotificationService extension module, which can accurately count the APNs display information above iOS10. This feature is too cool. APNs display data can not count the pain of developers and operators. I believe that with this feature, we can better track the arrival of APNs push. For specific integration steps, please see "http://docs.getui.com/mobile/ios/xcode/#6-ios-10-apns"."
After a successful push, you can check the push situation in a push background, as shown in the figure:
There is a clear distinction between a push channel. A successful push is sent through a push channel. After the APNs distribution module is offline, it is sent through the APNs channel. The display statistics mentioned above are the number of displays in the APNs module. The number of users is a little small, never mind, ha zZZ.
4. Differences in callback methods
APNs messages vary in App status, APNs message content, notification operation, and iOS system version, and callback methods are also different. The following picture is sent to me by the technician of a tweet the last time I was consulted. You can refer to it and be careful to test it when you use it to prevent the Apple system from changing again:
The transparent message of a tweet can be sent through the method ("GeTuiSdkDidReceivePayloadData: andTaskId: andMsgId: andOffLine:
FromGtAppId: ") callback acquisition, because Apple's APNs push does not guarantee arrival and arrival time, so it may be lost. The transparent transmission method of a push can better guarantee the arrival rate of the message than APNs.
At this point, I have to talk about a push mechanism. When our server pushes a message to a push server, the push server will check whether the push object is online (it should be judged by the heartbeat packet and network connection of a push SDK and a push server. If you do not receive a heartbeat packet after a certain period of time, it is "not online". However, this practice may lead to false online situation, that is, a sudden network outage. During the next time the server detects the heartbeat packet, the server thinks the object is online):
1) object online: send a push transparent message instead of APNs push message.
2) object offline: send a push transparent message and send an APNs push message.
As can be seen from the above, the transparent message of a push is sent every time, which also ensures the arrival rate of the message of the push. However, in this way, the message will be repeated, for example, a pop-up box to remind the user to operate, a push message and an APNs push message will be received. If the message is not handled properly, the user will be reminded of the same message for the second time.
The better thing here is that a push provides the "offLine" field in the transparent message method. When this value is "YES", it means that this is an offline message. When sending a push message, the APNs push message is also sent, which can be ignored when processing the message. If the importance of the message is not very high, you can do so, because the APNs message is not received after ignoring the push message, resulting in the loss of the message.
Another way to deal with it: with reference to some solutions on the Internet, I set up a configuration table, and the processed data is marked in the table to prevent the repeated operation of APNs and push transparent method messages.
5. Pay attention to tweeting and transmitting messages
Figure 1
Figure 2
In the above two pictures, the first is the interface when sending a transparent message on a push website, and the second is a push-through message callback method. It is important to note that the word "payload" at the bottom of the first picture and "payloadData" in the push-through method are not the same concept.
"payload" is a push custom field, which is added to the message content of APNs, not the native field of Apple. It will be sent to the iPhone client through the APNs push message. The structure is shown in the code block in the figure above. This field usually adds an accompanying message to the APNs message, such as a bar website url. When receiving a notification message, it is found that url,App directly opens the URL.
"payloadData" is the transparent message content, which corresponds to the "message content" on the figure. This field is not pushed to the iPhone client through APNs, but is sent directly to a push SDK through a push server. Of course, you can also set "message content" and "payload" to the same, depending on your specific usage.
Let's talk about "* split Android and iOS push tasks" in the first picture. If you select "Yes", after splitting the Android and iOS push tasks, two taskid will be generated to count and display the android and ios push data respectively, and then query the push data statistics later.
The last practical thing is a push "advanced notice", as shown in the following figure, all the fields in APNs push are listed, do not developers specifically remember which fields are in APNs, to facilitate some beginners who are not very familiar with APNs to use, not including me, of course.
6. Post to AppStore attention points
When App is published to AppStore, you need to replace the APNs certificate or the push AppId in App, because only one certificate can be uploaded in the website of each push, and the development APNs certificate is uploaded during development. When the development test is completed and ready for release, App needs the APNs certificate of the production environment. In this case, two solutions can be used:
1) create two sets of push AppId: this solution is to add two applications to a push website, one for development and one for publishing, the developed push AppId is used during development testing, and the published push AppId is used when publishing. This scheme needs to pay attention to switching AppId when publishing, and forget to switch to GG. It's okay to release for the first time, and the functions of the two push AppId can be exchanged. If it's an update release, Then it can only be resubmitted to Apple for approval.
2) replacement of APNs certificate: this solution is to re-upload the production APNs certificate at the time of release. Note that it takes about 10 minutes to take effect after the replacement of the push certificate. This solution needs to apply for a new push AppId when the version is updated and developed later, otherwise it will affect online customers.
I use the first solution, using two sets of push AppId, which is also recommended in the tweet document.
Third, the process difference between the company server pushing itself and using a push
1. The company server pushes its own (abbreviated as: self-push) process
1) register APNs and obtain DeviceToken
2) bind DeviceToken to user ID to save the server
3) when pushing, the DeviceToken is obtained according to the user ID, and the message content, DeviceToken and APNs push certificate are sent to the Apple server
2. Use a push process
1) register APNs and obtain DeviceToken
2) integrate push SDK, get ClientId, bind ClientId and DeviceToken
3) bind ClientId to user ID to save the server
4) when pushing, the ClientId is obtained according to the user ID, and the message content and ClientId are sent to a push server
Four: compare your own push with the third party
1. Cost: self-push requires a dedicated person for development, a certain number of servers and bandwidth support, and a dedicated person for maintenance during the use process after the completion of the development. Using third-party push, you only need to integrate SDK to realize the function, which not only reduces the development cost and maintenance cost, but also makes the third party better than the self-made push in terms of push stability.
2. Accurate push: you can accurately push information such as content and tags, such as pushing news from Hangzhou to Hangzhou users. Your own push requires additional development, and most third parties already support this feature.
3. Push statistics: push by yourself still needs additional development of this feature, which is basically required by third parties. Relatively speaking, the statistical effect of the push I use now is satisfactory. Distinguish between online distribution and APNs distribution statistics, support notification display statistics and click statistics, you can know the real number of posts, how many have been displayed and how many have been clicked.
4. Controllability: the controllability of using a third-party push is too low. Consider that if the third-party push vendor is down or is *, your service cannot be pushed, you need to wait for the third-party vendor to respond, or there is a problem with the third-party vendor. It will also affect your push. So those painful experiences tell us to choose a major to do push, such as a push, at least the number of users is 10 billion, and the server is hung up against him, .
To sum up: the cost of self-push is high, the service is relatively more controllable, and the cost of using third-party push is low, and there are more features. It is suggested that if the company is particularly large, it does not care about the cost and requires that the service can be controlled, and you can build your own push service. If it is a small company or a start-up company, it is more appropriate to use a third-party manufacturer. There is no unified answer. Should be constantly weighed and adjusted according to their own product characteristics and company conditions.
Five: use the feeling of putting off
1. During the development and testing, the push certificate was replaced, and it takes about 10 minutes to take effect after the certificate replacement. It feels troublesome during the test, so it can't take effect immediately.
2, push, you can automatically increase the corner label, product requirements, as a developer do not know what good, but the product requirements, can only be done, but also a push support.
3. You can count the display rate and click rate of the notification. After sending the notification, the operator students can know what kind of activities users are interested in, which is more convenient for them to operate.
4. Push to specified groups. For example, if we are active in Shanghai, we can assign it to Shanghai users to push vigorously. This is better, not all users need to send, to ensure that unrelated users will not be disturbed.
5. The transparent transmission method of a push can guarantee the arrival of the data, because Apple's APNs push does not guarantee the arrival and arrival time, so it may be lost. Using the transparent transmission method of a push can guarantee that the message can be received.
6. When sending transparent messages, the "code block" function in "iOS Advanced Notification" is quite good. I personally like it very much. I can preview the data format of the APNs notification message received by the client in advance.
The above is all the content of this article "sample Analysis of iOS APNs". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.