IOS integrated loop push and push, the most detailed process (Certificate creation, ring integration, testing)

These days the project used a push alliance, although not done before, but there are still a lot of details for a long time do not notice, so decided to start again from scratch, put every link with the same record, each pit also recorded. When is it convenient for yourself after the process can forget which see it again. I can understand that the problems encountered online Baidu a bunch of similar answers but not good, so I will I meet in the project are posted, I hope we can bring some reference and help,

One, push the principle and process (anxious to do push, you can skip this step)

First, we recommend an introduction to push mechanism excellent post: http://www.jianshu.com/p/e347f999ed95, which on the local and remote push push are introduced in detail, at least I see or feel harvest a lot. Especially there are a few pictures do not know where to find the blogger, but is really a see through, so good, so I came here 0.0. I steal the decisive push the process to do a simple narrative, and strive to use the most simple language to illustrate the mechanism of the push.

Take a picture first,

IOS integrated loop push and push, the most detailed process (Certificate creation, ring integration, testing)

One more move:

IOS integrated loop push and push, the most detailed process (Certificate creation, ring integration, testing)

When our apple mobile phone network, automatically with the apple server to establish long connection, long connection there are many benefits, such as system upgrades, time calibration, data transmission and response quickly and data can be kept up-to-date and other functions. The above two pictures about a simple push process:

  • 1 first of all, we need to convert the UDID and application of their equipment Bundle Identifier sent to Apple’s servers, then Apple server will return to us a DeviceToken, in my opinion this is the process of creating push certificate and description file.
  • 2 we will include mobile phone application package and label file upload to the server to do push up, when we started when the push message push from the back-end server, push server sends the DeviceToken message and we need to send Message to Apple’s APNS (Apple push Notification Service) server.
  • 3 when Apple’s servers need to send messages and receive DeviceToken Message, according to UDID to find the device in the DeviceToken, according to DeviceToken Bundle Identfier to find the application, and will be sent to the Message device.

Here is the instant messaging mechanism illustrated with the QQ server as a chestnut:

IOS integrated loop push and push, the most detailed process (Certificate creation, ring integration, testing)

the picture has been detailed enough, I will not cut in, begin our project below

Two. Specific process

We created a project called TestDemo, which I developed using Xcode8.1, the project named PushDemo, and created the project interface as follows (Xcode8)

IOS integrated loop push and push, the most detailed process (Certificate creation, ring integration, testing)

from Xcode8, Xcode provides automatic certificate management function, it is easy to use, after most places I am currently used in the project is to create a Demo, if you want to run the machine, you only need to select in the Team box to select my account, then there will be a below a prompt loading ring, etc. it finished loading can run on a real machine, this process is actually the development of Xcode using your current BundleId to the account of this center to create a corresponding AppId and description file, but since we are as a record of their own development process, to create these things, so, we choose Automatically manage to cancel the signing option. This interface is as follows:

IOS integrated loop push and push, the most detailed process (Certificate creation, ring integration, testing)

Well, we’re going to officially start our work, GO GO GO!

1. first of all, let’s go to the official website to create AppID and description files

We are going to push the integration, so we need to use the CER file, this thing is actually the apple to a certificate issued by the developer, we need to import it into our AppId configuration, otherwise is unable to push the integration, installation should remember when prompted to install such as “the application of” certification information publisher, I guess the mark that the CER file is our identity, we can make application development for people’s normal installation and use, there is a very detailed post on the certificate, the certificate of information to understand the reader can do: http://m.blog.csdn.net/article/details id=8617788?

Create the CER file of the process is very simple, open the keychain access (although very good, but still hope to come out, afraid of children lost)

IOS integrated loop push and push, the most detailed process (Certificate creation, ring integration, testing)
IOS integrated loop push and push, the most detailed process (Certificate creation, ring integration, testing)

After you open the key string, click “request certificate” from the certification authority “

IOS integrated loop push and push, the most detailed process (Certificate creation, ring integration, testing)

Fill in the mailbox and frequently used names. Remember the options box below and select “store to disk”

IOS integrated loop push and push, the most detailed process (Certificate creation, ring integration, testing)

Click storage

IOS integrated loop push and push, the most detailed process (Certificate creation, ring integration, testing)

It’s already saved on the desktop

IOS integrated loop push and push, the most detailed process (Certificate creation, ring integration, testing)

Here we have created the CER file, and then we go to the developer center to create the AppId and the description file

2. create AppId and description files

First of all, into the developer center, Baidu search Apple Developer (hey, really detailed home, ah, I can’t go on)
, figure

IOS integrated loop push and push, the most detailed process (Certificate creation, ring integration, testing)

Enter the developer account, log in,

IOS integrated loop push and push, the most detailed process (Certificate creation, ring integration, testing)

You’ll see this page,

IOS integrated loop push and push, the most detailed process (Certificate creation, ring integration, testing)

Click to see:

IOS integrated loop push and push, the most detailed process (Certificate creation, ring integration, testing)

enter the AppId file name and BundleId

IOS integrated loop push and push, the most detailed process (Certificate creation, ring integration, testing)

select the following PushNotifications

IOS integrated loop push and push, the most detailed process (Certificate creation, ring integration, testing)

click Continue:

IOS integrated loop push and push, the most detailed process (Certificate creation, ring integration, testing)

click register:

IOS integrated loop push and push, the most detailed process (Certificate creation, ring integration, testing)

click Done to go back to the AppId list page

IOS integrated loop push and push, the most detailed process (Certificate creation, ring integration, testing)

can see our AppID on the AppId list page,

IOS integrated loop push and push, the most detailed process (Certificate creation, ring integration, testing)

But it’s not finished yet, because we’re going to do push, so you need to upload our cer file
, click our AppId, and in the details of the expansion, you can see:

IOS integrated loop push and push, the most detailed process (Certificate creation, ring integration, testing)

Two lights Push Notification or yellow, we want to enable it, click Edit in the opening pages of the slide to the bottom, remember to Push the Notification button is selected, and then click on the top of the development of the button to create a certificate certificate:

IOS integrated loop push and push, the most detailed process (Certificate creation, ring integration, testing)

Click Continue

IOS integrated loop push and push, the most detailed process (Certificate creation, ring integration, testing)

Click choose file:

IOS integrated loop push and push, the most detailed process (Certificate creation, ring integration, testing)

Pass the certificate we requested from the developer, and then click Register:

IOS integrated loop push and push, the most detailed process (Certificate creation, ring integration, testing)

Click on the page after Register, click download, download it to the desktop, and after download, remember to click Done to complete the file creation:

IOS integrated loop push and push, the most detailed process (Certificate creation, ring integration, testing)

File on desktop:

IOS integrated loop push and push, the most detailed process (Certificate creation, ring integration, testing)

Now we’ve finished creating the developer certificate for AppID, and then we’ll create a publisher certificate for it, click Done and then go back to the AppIds list, and if not, click the App IDs
on the right

IOS integrated loop push and push, the most detailed process (Certificate creation, ring integration, testing)

Open the project AppId, the interface is as follows, click on the following CreateCertificate, AppID began to create a publisher to create a publisher certificate, AppId certificate process to create developer certificate is the same! To AppId to create a publisher certificate to create the process developer certificate is the same! To AppId to create a publisher certificate process to create developers the certificate is the same! Something important to say three times!! because I’m not put out to create a release certificate according to the map, so you create a development certificate process again good, also will be released to the local certificate Download:
.

IOS integrated loop push and push, the most detailed process (Certificate creation, ring integration, testing)
IOS integrated loop push and push, the most detailed process (Certificate creation, ring integration, testing)

When created, when you return to this page, you should display as follows:

IOS integrated loop push and push, the most detailed process (Certificate creation, ring integration, testing)

At this point, we download the following files:

IOS integrated loop push and push, the most detailed process (Certificate creation, ring integration, testing)

Then drag the two certificates into the key string, and the steps are as follows:
first open the key string:

IOS integrated loop push and push, the most detailed process (Certificate creation, ring integration, testing)
IOS integrated loop push and push, the most detailed process (Certificate creation, ring integration, testing)

then click: system certificate, and then the two file drag, you will be prompted to enter the password, enter the like (recommended to add before the interface screenshots, add after contrast can just add those files)

IOS integrated loop push and push, the most detailed process (Certificate creation, ring integration, testing)

After adding is like this, the picture frame is our certificate

IOS integrated loop push and push, the most detailed process (Certificate creation, ring integration, testing)

Then select the “login” option on the left to see the certificate
we just created

IOS integrated loop push and push, the most detailed process (Certificate creation, ring integration, testing)

select the first certificate, and then right-click (you know the right key), select export…

IOS integrated loop push and push, the most detailed process (Certificate creation, ring integration, testing)

Select the export P12 file, stored in the table, access to the P12 file. For the same operation on the two certificate. (remember the title (Develop) and the name for the Product file, it derived second certificate named Develop, can set their own name, just to do)

IOS integrated loop push and push, the most detailed process (Certificate creation, ring integration, testing)

will then prompt you to enter the password, here I set the password is zx123456, set their own, must remember, and later use.

IOS integrated loop push and push, the most detailed process (Certificate creation, ring integration, testing)

then you can see our exported P12 file on the desktop,

IOS integrated loop push and push, the most detailed process (Certificate creation, ring integration, testing)

Now we have completed the creation of all certificates, you can go to the letter to create our application

3 create a real machine debugging file and imported into the project

Because must carry out testing, and we turn off the automatic management certificate, leading to Xcode8 does not automatically generate a certificate for us, so we need to create a real machine debugging certificate and imported into the project, the process is as follows:

Creating a description file:

IOS integrated loop push and push, the most detailed process (Certificate creation, ring integration, testing)

Select the development model, next:

IOS integrated loop push and push, the most detailed process (Certificate creation, ring integration, testing)

Select the corresponding AppID, and select the AppId:
we just created

IOS integrated loop push and push, the most detailed process (Certificate creation, ring integration, testing)

Select the development team, I usually select the next step:

IOS integrated loop push and push, the most detailed process (Certificate creation, ring integration, testing)

Select the device debugging machine, select the next step:

IOS integrated loop push and push, the most detailed process (Certificate creation, ring integration, testing)

Next step:

IOS integrated loop push and push, the most detailed process (Certificate creation, ring integration, testing)

Download the created description file and put it on the desktop:

IOS integrated loop push and push, the most detailed process (Certificate creation, ring integration, testing)

Create a description file:

IOS integrated loop push and push, the most detailed process (Certificate creation, ring integration, testing)

First select the prototype debug model download debugging description file:

IOS integrated loop push and push, the most detailed process (Certificate creation, ring integration, testing)

Select the profile that you just downloaded on your desktop:

IOS integrated loop push and push, the most detailed process (Certificate creation, ring integration, testing)

Use the same steps to select Release mode prototype debug file, the operation does not map as like as two peas,. After all two files are imported into the plug machine, it can be a real machine debugging.

4. create our applications in the loop

First of all, Baidu search ring letter, open their official website, first registered account, registered can skip, above:
registration time, select “registered instant messaging cloud”

IOS integrated loop push and push, the most detailed process (Certificate creation, ring integration, testing)

Registration when you need to fill in all kinds of information, in accordance with the format to fill in, and then fill in after landing, click on the creation of application

IOS integrated loop push and push, the most detailed process (Certificate creation, ring integration, testing)

Fill in application information

IOS integrated loop push and push, the most detailed process (Certificate creation, ring integration, testing)

Fill in as shown below,

IOS integrated loop push and push, the most detailed process (Certificate creation, ring integration, testing)

Then we need to upload our P12 file, the picture is very clear – not to mention, for the first time I chose to upload the production certificate:

IOS integrated loop push and push, the most detailed process (Certificate creation, ring integration, testing)

Second upload Development Certificate:

IOS integrated loop push and push, the most detailed process (Certificate creation, ring integration, testing)

So far, we have developed the certificate upload finished, a long way to integrate ring letter into code.

5. integrated ring letter to the project

First, download the latest SDK here (as of the latest SDK for writing this article)

Http://www.easemob.com/download/im link push SDK download link

Click on the latest SDK download from iOS, which is downloaded from V3.x’s SDK

IOS integrated loop push and push, the most detailed process (Certificate creation, ring integration, testing)

Download to the desktop is the ghost like

IOS integrated loop push and push, the most detailed process (Certificate creation, ring integration, testing)

We only need to circle the two folder guide into the project is good, the other is

IOS integrated loop push and push, the most detailed process (Certificate creation, ring integration, testing)

After entering, the list of files is like this, the compiler will make mistakes, do not worry, and slowly change.

IOS integrated loop push and push, the most detailed process (Certificate creation, ring integration, testing)

Add the required library
to the project

IOS integrated loop push and push, the most detailed process (Certificate creation, ring integration, testing)

The above picture is an official document of the intercepted ring letter. I added it like this:

IOS integrated loop push and push, the most detailed process (Certificate creation, ring integration, testing)

Text:
CoreMedia.framework library to facilitate replication of
AudioToolbox.framework
AVFoundation.framework
MobileCoreServices.framework
ImageIO.framework
libc++.dylib
libz.dylib
libstdc++.6.0.9.dylib
libsqlite3.dylib
(if you are using xcode7, suffix TBD.)
this step is important because SDK does not support bitcode, so set NO in Build, Settings, Linking, Bitcode, Enable.

IOS integrated loop push and push, the most detailed process (Certificate creation, ring integration, testing)

Command+B compilation project, a lot of red. Don’t worry, modify our PCH file just fine,
in the PCH file to add
‘#ifdef OBJC

#import < UIKit/UIKit.h>

Endif’

We can solve this problem by putting all of our definition and additions of header files and macro definitions in the middle of #ifdef, OBJC, and #endif.

Then push the push in the project:

IOS integrated loop push and push, the most detailed process (Certificate creation, ring integration, testing)

6. test whether integration success

First, let’s go to the back of the loop to add a user
to our application

IOS integrated loop push and push, the most detailed process (Certificate creation, ring integration, testing)

User name is set as: 13051698888 password set to: 222222

IOS integrated loop push and push, the most detailed process (Certificate creation, ring integration, testing)

Then we went to the appledate.m file to add something, a very important step, ADO, directly affixed to it need to configure the code directly to use 0, need to add something in the notes in the notes I quite understand… Remember to guide in the header file

Import “EMSDK.h””

@interface AppDelegate (<); EMChatManagerDelegate> @end @implementation AppDelegate (BOOL) application: (UIApplication * application) didFinishLaunchingWithOptions: (NSDictionary * launchOptions) {//AppKey: AppKey registration, click on the "application" can be seen in AppKey, you can paste over. //apnsCertName: pushes the certificate name, writes your development certificate, or issues a certificate name, which is one of the two uploaded to the ring back office, and what environment tests the certificate of what environment to use. EMOptions *options [EMOptions optionsWithAppkey:@ = "1192161108178165#testpushdemo"]; @ options.apnsCertName = "Develop"; [[EMClient sharedClient] initializeSDKWithOptions:options]; / / here is the use of ring letter I have created the account name and password in the ring channel background, use the account login, if the message sent to the client in the background, you can find the user [[EMClient sharedClient] loginWithUsername:@ "13051698888" password:@ "222222" completion:^ (NSString *aUsername, EMError *aError) {if (! AError) {NSLog (@ "ring letter landed"); EMPushOptions *emoptions = [[EMClient sharedClient] pushOptions]; / / set the display mode with a message came: 1 received a message for 2 specific message content. You can test the emoptions.displayStyle / EMClient + sharedClient] = EMPushDisplayStyleSimpleBanner; updatePushOptionsToServer];} else {NSLog (@ "ring letter login fails");} / * *}]; registered APNS offline push iOS8 registration APNS * / if ([application respondsToSelector:@selector (registerForRemoteNotifications)]) {[application registerForRemoteNotifications]; UIUserNotificationType notificationTypes = UIUserNotificationTypeBadge UIUserNotificationTypeSound | | UIUserNotificationTypeAlert; UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:notificationTypes categories:nil]; [application registerUserNotificationSettings:settings];} else{UIRemoteNotificationType notificationTypes = UIRemoteNotificationTypeBadge UIRemoteNotificationTypeSound | | UIRemoteNotificationTypeAlert; [[UIApplication sharedApplication] registerForRemoteNotificationTypes : notificationTypes];} / / add monitor online push message [[EMClient sharedClient].chatManager addDelegate:self delegateQueue:nil]; return YES;} / / monitor ring letter online push message - (void) messagesDidReceive: (NSArray * aMessages{) UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:@ "that" message:@ "ring letter received notice" delegate:nil cancelButtonTitle:@ "Cancel" otherButtonTitles:@ "OK" nil]; [alertView, show]; //aMessages is an object that contains all the information sent, how to extract the information I posted in the back.} will be passed to the deviceToken / SDK - (void) application: (UIApplication * application) didRegisterForRemoteNotificationsWithDeviceToken: (NSData *) deviceToken{[[EM Client sharedClient] bindDeviceToken:deviceToken];} / / deviceToken registration failed - (void) application: (UIApplication * application) didFailToRegisterForRemoteNotificationsWithError: (NSError *) error{NSLog (@ error -% @ ", error);} / / APP - (void) applicationDidEnterBackground: into the background (UIApplication * application) {[[EMClient sharedClient] applicationDidEnterBackground:application];} / / APP will be from the background return - (void) applicationWillEnterForeground: (UIApplication *) application sharedClient] {[[EMClient applicationWillEnterForeground:application];}

Several of the above methods must be rewritten in appdelegate, or they will cause the push to fail directly:

  • Circular notifications can only be received when the application is completely exited and killed;
  • If you want to send an online notification, you need to get the ring push message in the messagesDidReceive method, then launch a local notification to the user, which can be studied by yourself
  • By setting emoptions.displayStyle = EMPushDisplayStyleSimpleBanner, (the code above), you can set the display mode when a notification comes in, display a hint, or display the full message
  • Upload the application package under the certificate, refer to your BundleID!!! I stepped on the pit here, remember!! .

Test push:

  1. In the case of application completely exit (registered with the ring letter account login once, after confirmation of a successful login again, completely out) we selected users, click send message:
    IOS integrated loop push and push, the most detailed process (Certificate creation, ring integration, testing)

Click send:

IOS integrated loop push and push, the most detailed process (Certificate creation, ring integration, testing)

Test result:

IOS integrated loop push and push, the most detailed process (Certificate creation, ring integration, testing)

2 test program online push, or send a “hello”, and then we intercept ring letter in the messagesDidReceive EMMessage object, EMMessage object for analytical methods are as follows, the complete ring letter extraction method for push message:

- (void) messagesDidReceive: (NSArray *) aMessages{UIAlertView *alertView [[UIAlertView alloc] initWithTitle:@ = "tip" message:@ "ring letter received notice" delegate:nil cancelButtonTitle:@ "Cancel" otherButtonTitles:@ "OK", [alertView show]; for nil]; (EMMessage *message in aMessages EMMessageBody) {*msgBody = message.body; switch (msgBody.type) {case {/ / EMMessageBodyTypeText: received the text message EMTextMessageBody *textBody = (EMTextMessageBody *) msgBody NSString; *txt = textBody.text; NSLog (@ "received text is txt -% @", txt);} break; Case EMMessageBodyTypeImage: {/ / get a picture message of body EMImageMessageBody (*body = (EMImageMessageBody * msgBody)); NSLog (@ remote path% @ ", body.remotePath); NSLog (@ local path% @", body.localPath); / / / / need to use SDK to provide download method only after NSLog (@ "the big picture of the secret - body.secretKey); NSLog% @, (@" large W -%f, H - large%f, body.size.width, body.size.height); NSLog (@ "big picture download status -%u, body.downloadStatus); / / SDK thumbnails will automatically download the NSLog (@ little figure remote path ", body.thumbnailRemotePath); NSLog% @ (@" local "-- a small map path,% @ body.thumbnailLocalPath); NSLog (@" secret "-- a small map, body.thumbnailSecretKey% @ (@ NSLog);" small figure of W -%f, H -%f, larger body.thumbnailSize.width, body.thumbnailSize.height); NSLog (@ "download the map --%u, body.thumbnailDownloadStatus);} break {EMLocationMessageBody = case; EMMessageBodyTypeLocation: *body (EMLocationMessageBody * msgBody); NSLog (@%f", "latitude - body.latitude); NSLog (@"%f ", body.longitude - longitude); NSLog (@ address:" "% @ body.address), break case EMMessageBodyTypeVoice:;}; {/ / audio SDK will automatically download EMVoiceMessageBody *body = (EMVoiceMessageBody * msgBody); NSLog (@" remote ", audio path -% @ body.remotePath); NSLog (@" local ", audio path -% @ body.localPath); / / there will need to download the method provided by SDK after (audio will automatically call (NSLog) @" secret audio ", body.secretKey -% @ (@ NSLog);"%lld "-- the size of audio files, body.fileLength); NSLog (@" audio file download status -%u ", body.downloadStatus); NSLog (@ "audio length of time --%u, body.duration);} break {EMVideoMessageBody = case; EMMessageBodyTypeVideo: *body (EMVideoMessageBody * msgBody); NSLog (" remote video @ path --% @ ", body.remotePath); NSLog (" local video @ path --% @ ", body.localPath); / / NSLog will need to download the method provided by SDK (after" secret video @ -% @ ", body.secretKey); NSLog (@" video file size%lld, body.fileLength); NSLog (@ "video file download status -%u, body.downloadStatus); NSLog (" the video @ The length between -%u ", body.duration); NSLog (@" video W -%f, H -%f "video, body.thumbnailSize.width, body.thumbnailSize.height); / / SDK thumbnails will automatically download the NSLog (@" thumbnail remote path ", body.thumbnailRemotePath -% @ (@ NSLog);" local "-- the thumbnail path% @. Body.thumbnailLocalPath); NSLog (secret -% @ @" thumbnail ", body.thumbnailSecretKey); NSLog (@" thumbnail download status -%u ", body.thumbnailDownloadStatus);} break {EMFileMessageBody = case; EMMessageBodyTypeFile: *body (EMFileMessageBody MsgBody NSLog (@ *); "remote file path -% @", body.remotePath); NSLog ("local @ file path% @", body.localPath); / / NSLog will need to download the method provided by SDK (after the @ secret file -% @ ", body.secretKey); NSLog (@" file size -%lld, body.fileLength); NSLog (@ file download status -%u, body.downloadStatus); break default: break;};}}}

After sending successfully, the print results are as follows:

The text received by 2016-12-01 16:03:26.060088 PushDemo[1392:450230] is TXT -- hello

Three. Epilogue

At this point, we have successfully integrated the “ring letter” to our project. In addition, we provide some small methods that are often used when pushing

  • Sets the application icon in the upper right corner corner. UIApplication *application digital = [UIApplication sharedApplication]; [application setApplicationIconBadgeNumber:3];
  • If the push certificate does not look particularly clear, provide a link to create a push certificate: http://www.jianshu.com/p/78282e16db66
  • Set the APNs nickname for push over: [[EMClient, sharedClient], setApnsNickname:@, “push nickname”;

Always take the time to write this blog, usually busy no time to write and record the bulk of these things, but nothing to write a little put all sorts of things together, eventually finished. Hope to see here buddy can be successfully integrated ring channel push, can be a problem in the following message, I will reply to see buddy. I hope the crowd can not appear in this blog post pointing error, whether text error or logic errors and so on, I will not leave as soon as possible amendments to future generations. The pit…

Give the project gitHub address:
https://github.com/TheRuningAnt/PushDemo.git, if you like, remember to give the little star ha!

There may be a problem with the layout in Jane’s book. The original blog address is http://blog.csdn.net/mumubumaopao/article/details/53423393