IOS APNs Combat Sharing

Source: Internet
Author: User


Because the function needs of the app, recently has been in the investigation of Apple APNs push, beginning to feel super trouble, now feel is relatively easy, "difficult people will not, will not be difficult", he stepped on so many pits finally will, do not come out to spit Groove (Pack x) sorry myself, 23333.

First give everyone a small benefit, because APNs can only be tested on the real machine, the simulator can not use, if not the iphone classmate, may take this opportunity to find the boss to apply for an iphone, can apply to see the ability, I just do not have the iphone, Then let the company help with the iphone in this way.

Then is the need to write service code, in the test send APNs message, need to write server code to the Apple server to send messages, I as a pure iOS developer, the server code ten out of nine out of the way, fortunately, many third parties online now provide this feature, because our company uses a push, Just use a push to provide the function test, do not need me to write server code really cool.

Preparatory work:

1, Apple development license, is divided into: Development certificate (IOS app development), Production certificate (app Store and Ad Hoc), and so on, I use a development certificate for testing.

2, Apple developer website registered "Appids", I use "Com.crazywolf.yewan", tick "Push notifications".

3, the real machine (refueling, the iphone is waiting for you), need to be added to the development license device.

4, Provisioning

Profiles files, points: used during development (IOS app development), production (app Store, Ad Hoc), etc., I use "development" later.

5, Apple APNs push Certificate, Sub: Development Environment Certificate (development), Production Environment certificate (Production), and so on, also use "development", note use push platform APNs push to upload the push certificate, Here I submit the Export development environment certificate to push platform, about certificate production and export can view a push APNs configuration technical document ( )。

6, Xcode8.2 (different version in the configuration is a bit different), the minimum support version of iOS 8.0.

One: Register APNs, get Devicetoken

1. Create a new project or modify an old project, configure a project

2, register APNs, get Devicetoken

3, use a push test, test Devicetoken

is not very simple, so you can get to APNS push message, there is a sense of success, but I started to get Devicetoken, always reported ("Error Domain=nscocoaerrordomain code=3000

"The authorization string for" Aps-environment "of the application not found" userinfo={nslocalizeddescription= not Found "aps-environment" authorization string for the application ") error, Online said is the certificate is not configured well, I reconfigured a number of certificates or not, and then asked a push technical support to know Xcode8 above version needs to open "TARGETS-

Capabilities-push notifications ", a push of the integration document is also written, oneself too careless.

4, APNs environmental problems

Note Keep The push APNs environment consistent with your app push environment, because often someone will mistake the certificate environment, causing the push to be received.

1) directly using Xcode directly to the phone, according to the "TARGETS

Signing "Provisioning profile" and "Signing Certificate" to confirm. For example:

To share, I have a habit of naming "Provisioning profile" with "Dev:" (development environment), "in House:" (Enterprise Package Environment), "XC Ad Hoc:" (bundle environment), "XC:" (App Store), Three of these are production environments.

2) packaged into an IPA package installed on the iphone, may forget the package when the configuration or other people to send your package, is it possible to know APNS environment? Early on, my approach was to get the app's Devicetoken, use the development and production environment APNs certificates to push, and see which one can be pushed to. Later found that there are other methods, that is to parse the IPA package:

1) First unpack the IPA package, find the. app file, display the package contents

2) Locate the. mobileprovision file and use Atom to open the. mobileprovision file

3) Look for "aps-environment", View "aps-environment" This key value corresponds to value, "development" represents the development environment, "production" represents the production environment. Such as:

Second: Formally push the APNs, push to send the information we need

1, integration of the Push SDK

How to configure a push, you can go to see "", the configuration after successful run to get a push "clientId".

2, the use of a push website on the "transmission message" issued

This can push the custom message content to the iphone, to here APNs function has been completed, the back of the need to look at the specific needs, will be a push the service side of the integration to the service developers, let him "code" up, if there is a problem, let them contact a push technical support, 2333.

3, APNs News statistics

Push the latest version 1.5.3 iOS SDK added the "iOS APNs Display Statistics" feature, which uses the iOS10 new features need to add notificationservice extension module, can accurately statistics iOS10 APNs display information, this feature is too cool , APNs display data can not be counted how many developers and operating pain Ah, I believe that with this feature can better track APNs push arrival situation. You can see "" for specific integration steps.

After the push is successful, you can view the push situation in a push background.

A push channel issued or distinguish pretty clear, a push successfully issued for through a push channel issued, APNs successfully issued module for offline, go APNs channel issued, which said the display statistics is APNs module display number. The user is a little bit small, do not mind the AH zzz.

4. Callback Method Difference

APNs message in different state of the app, APNs message content, notification action, iOS system version, the callback method is different, the following picture is the last time a push, a push technician sent me, you can refer to see, note the use of testing, to prevent the change in the Apple system:

A push-through message can be passed by means of the method ("GeTuiSdkDidReceivePayloadData:andTaskId:andMsgId:andOffLine:

Fromgtappid: ") callback is obtained, because Apple's APNs push does not guarantee the arrival and arrival time, so it may be lost, using a push-through method relative to APNs more secure the arrival rate of the message.

Speaking of which we have to say a push the push mechanism, in our service to push the server push the message, the push server will check whether the push object is online (should be based on a push SDK and a push server heartbeat packet and network connection judgment, more than a certain period of time did not receive a heartbeat package is "not online", However, this practice may occur fake online situation, that is, suddenly off the network, the next time the server detects heartbeat packet, the server will consider the object online):

1) Object online: issued a push through the message, do not send APNs push message.

2) object offline: Send a push-through message, sending APNS push message.

From the above can be seen, a push through the message is issued every time, so that also guaranteed a push of the message arrival rate, but this practice will be repeated message, for example, received a message box alert user Action, a push-through message and APNS push messages are received, processing bad words will remind users two times the same message.

What's better is a push in the pass-through message method provides the "OffLine" field, the value is "yes" when it means that this is an offline message, in the issuance of a push-through message, also sent a APNS push message, in processing the message can be ignored, if the message is not very important, you can do so, This message is lost because the APNS message is not received after ignoring a push-through message.

Another way of processing: referring to some of the online solutions, I set up a configuration table, processed data in the table labeled, to prevent APNs and a push through the method of message duplication operation.

5, a push-through message attention point

Figure 1

Figure 2

Above two pictures, the first one is a push website when the message is sent through the interface, the second is a push-through message callback method. Special attention should be paid to the "Payloaddata" in the bottom "payload" and the push-through method in the first diagram, which is not the same concept in the two.

"Payload" is a push custom field, added in the APNs message content, not the Apple native field, will be sent to the iphone client via APNs push message, structure such as code block display, this field is generally in the APNS message to add the accompanying message, For example, with a bar website URL, when you receive the notification message is, found to be url,app directly open this URL.

"Payloaddata" is the content of the message, corresponding to the " message content" On the map, this field will not be pushed through APNs to the iphone client, through a push server directly issued to a push SDK. Of course, you can also set the "message content" and "payload" to the same, this depends on your specific use of the situation to be decided.

Say the first in the "* Split Android and iOS push task", select "Yes", will be split between Android and iOS push task, will generate two TaskID, respectively, Android and iOS push data statistics and display, easy to query push data statistics.

The last more practical is a push "advanced notice", such as the APNs push the fields are listed, not developers deliberately remember what fields in APNs, convenient to APNs is not very familiar with beginners use, of course, not including me, haha haha.

6. Post to AppStore note

When the app is published to AppStore, you need to change the APNS certificate or change the app in a push AppID, because a push site can only upload a certificate, the development of the upload is the development APNs certificate, when the development test is completed, ready to publish, the app needs the production environment APNs certificate, There are two options to use:

1) Create two sets of push AppID: This scenario is to add two apps to a push site, one for development, one for publishing, and a push appid for development during development testing, using a published push AppID when publishing, which requires attention to switching AppID at release, forgetting to change GG, The first release fortunately, two push the role of AppID swap on it, if the update is released, it can only resubmit the Apple audit.

2) Replace the APNS certificate: This scheme is to re-upload the production APNs certificate at the time of release, note that a push certificate replacement takes effect after 10 minutes, this scheme needs to be aware that in the later version update development, you need to apply for a new push AppID, otherwise it will affect the online customers.

I am using the first scenario, using two sets of push AppID, which is also recommended for the first scenario in a push document.

Three: The company server itself pushes and uses a push-push process difference

1, the company server self-push (referred to as: their own push) process

1) Register APNs, get Devicetoken

2) Bind the Devicetoken and user ID to save the server

3) When push, get to Devicetoken based on user ID, send message content, Devicetoken and APNs push certificate to Apple server

2, the use of a push-push process

1) Register APNs, get Devicetoken

2) Integrate a push SDK, get ClientID, bind ClientID and Devicetoken

3) Bind the ClientID and user ID to save the server

4) When the push, according to the user ID to get to ClientID, the message content and ClientID sent to a push server

Four: Self-push and third-party comparison

1, cost: Their own push needs special personnel for development, and need a certain number of servers and bandwidth support, in the development after the use of the process also requires someone to maintain. With third-party push, only the integration SDK can be used to achieve functionality, not only reduce development costs and maintenance costs, even in the push stability of the third party will be better than their own push.

2, Precision push: Can be targeted for content and label information such as accurate push, such as Hangzhou's news to Hangzhou users, their own push needs additional development, and the majority of the third party has supported such a function.

3, Push statistics: their own push back is the need for additional development of the function, and the third party basic must be the function, relatively speaking, I now use a push statistical effect is still satisfactory, distinguish the online issued and APNs issued statistical functions, support notification of the display statistics and click Statistics, you can know the real volume, How many were displayed after the release, how many were clicked on.

4, Controllability: The use of third-party push controllability is too low, think, if the third-party push vendors down, or hacked, your service can not be pushed, you need to wait for a third-party vendor response, or a third-party vendor problem, will also affect your push. So those painful experience tells us to choose home professional to do push, such as a push, at least others are also company aims Yangzhou user volume, the server hung godless he went, haha.

Summary: The high cost of their own push, the relatively more controllable service, the use of third-party push cost is low, more features. If the company is particularly large, the cost does not care about the requirements of services can be controlled, you can set up a push service, if it is a small company or entrepreneurial company, the use of third-party manufacturers more appropriate, there is no unified answer, according to their own product characteristics, the company constantly weigh and adjust.

Five: The use of a delayed feeling

1, in the development of testing, the replacement of the push certificate, the certificate will take about 10 minutes after the replacement of the effective, the test feel good trouble, can not immediately take effect.

2, push, you can automatically increase the angle mark, product demand, as a developer do not know what good, but products such requirements, can only do, fortunately a push support.

3, can be statistical notification of the display rate and click-through, the operation of students can be in the push activity notification, know what kind of activities users are interested in, more convenient for them to operate.

4, can be pushed to the designated population, such as our activities in Shanghai, can be designated to Shanghai users push strongly. This is better, not all users are sent to ensure that irrelevant users are not disturbed.

5, a push through the transmission method can guarantee the arrival of data, because Apple APNs push is not guaranteed arrival and arrival time, so it may be lost, using a push-through method can be guaranteed to receive the message.

6, in the transmission of the message, "iOS Advanced Notification" in the "code block" function is like, I personally love, you can preview in advance the client received the APNS notification message data format.

IOS APNs Combat Sharing

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: 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.