IOS ---- youmeng push explanation, ios ---- explanation

Source: Internet
Author: User

IOS ---- youmeng push explanation, ios ---- explanation

I have carefully studied the push feature over the past two days. I will divide it into two parts: 1. IOS Mobile Phone, 2. Servlet server. Let's talk about IOS first today.

I. Feelings

Next, let's talk about how I feel about pushing this feature in IOS. This is an experience after I have implemented the server and mobile phone functions, this feature makes me feel a little confused on IOS. First, I often receive the push delay, and if I push two messages to an Iphone in a row, if latency occurs, the first push will be overwritten. (Here I am using umeng's push. This push temporarily feels good. Most pushes can be received in a timely manner. At least I tested it temporarily, so I chose it here, A third-party push that was only available two hours ago ..... it cannot even be received .), Again, even if the problem of delay is solved, the management of push messages is also a headache. If you want to manage it well, I think you must first create a corresponding notification management table in the database, today, I have carefully tested this function on IOS. When an application is removed from the background, the push messages received will not enter the notification proxy, which is a headache, (This reminds me of creating the corresponding table in the database .), It should be because the user cannot keep holding his or her mobile phone. Even if he or she takes his or her mobile phone, he or she may not see what the background push is, in this case, the application is removed from the background. For this reason, the received notification cannot enter the notification proxy, so the notification cannot be saved locally. Therefore, it is necessary to create a table. However, I found that many applications did not do this. If this is done, it is a great Optimization for pushing, at least on IOS, because IOS cannot completely avoid the worry of failing to receive notifications for the time being, in addition, I don't think the sent message content is important. It is important to modify the voice of the notification... so that you can view the new message in the notification table ....

 

2. Download umeng push SDK and integrate it into the application

I will not talk about registering here. I will explain it in the following ways.

1. Click "SDK download and documentation" below"

2. After executing the preceding step, go to the new page and find message push.

3. After executing the preceding step, go to the new page and click Download SDK.

 

4. COPY the downloaded SDK push package to the project.

3. Export the push certificate and upload it to umeng to create an application

1. You only need to export the P12 certificate for umeng push. You do not need to generate the pem certificate. here you need to export two certificates: one is the developer certificate and the other is the product Certificate.

If you still do not know how to make Ios push certificate, you can go to the http://www.cnblogs.com/xiaoliao/p/4928873.html to view, speak very detailed.

2. The following describes how to create an IOS app by umeng.

First, go to the account management background. You can click my products in the upper-right corner of the home page.

Click + Add new application in the lower left corner of the page.

Go to the create application page and create an application. I will show you how to create an application.

After the preceding steps are completed, drag the browser scroll bar and you will see the following

Next I want to explain. After you finish the above steps, you will create a push function for the selected application. Then, you will see the following content for this application:

You can modify the style as follows. Even if the certificate is incorrect in the previous step or other operations are incorrect, you can modify it after creation. Below is, here

The key point is to increase the Server IP address. If no Server IP address is added here, the WEB server cannot push notifications to your mobile phone. The IP address here is the IP address set up to the server by Servlt.

It is the servlet interface push on the local machine, so it is the IP address of my local machine. If it is set up on the server, the IP address will be changed to the IP address of the server.

 

 

4. Code for implementing the push function on IOS

1. Only part of the notification code is pasted. Authorization is allowed in Appdelegate. m.

-(BOOL) application :( UIApplication *) application didfinishlaunchingwitexceptions :( NSDictionary *) launchOptions {// asdf; lajksdfl; asdfl;/* UMessage startWithAppkey: @ "success? "LaunchOptions: launchOptions]; # if _ parameters> = _ IPHONE80 _ if (Response (@" 8.0 ") {uimutableusericationicationaction * action1 = [[UIMutableUserNotificationAction alloc] init]; action1.identifier = @ "action=identifier"; action1.title = @ "Accept"; action1.activationMode = success; // when clicked, start the program UIMutableUserNotificationAction * action2 = [[UIMutableUserNotificationAction alloc] init]; // The second button is action2.identifier = @ "action2_identifier"; action2.title = @ "Reject"; action2.activationMode = enabled; // when clicked, the program is not started and action2.authenticationRequired = YES is processed in the background; // unlock required for processing, if action. activationMode = UIUserNotificationActivationModeForeground; this attribute is ignored; action2.destructive = YES; uimutableusericationicationicationcategory * categorys = [[UIMutableUserNotificationCategory alloc] init]; categorys. identifier = @ "category1"; // the unique identifier of this group of actions [categorys setActions: @ [action1, action2] forContext :( category)]; UIUserNotificationSettings * userSettings = [UIUserNotificationSettings settingsForTypes: CATEGORY | uiusernotiftypesound | category categories: [NSSet setWithObject: categorys]; [UMessage classification: userSettings];} else {// register remoteNotification types (iOS 8.0 or lower) [UMessage classification: UIRemoteNotificationTypeBadge | uiremotenotiftypetypesound | audio] ;}# else // register remoteNotification types (iOS 8.0 or lower) [UMessage types: UIRemoteNotificationTypeBadge | uiremotenotiftypetypesound | audio] # endif // for log [UMessage setLogEnabled: YES];}

2. register the device Token

-(Void) application :( UIApplication *) application didregisterforremotenotifswswithdevicetoken :( NSData *) deviceToken {// the token below converts the obtained nsdata to a String, this should be passed to the server when the push is specified. NSString * token = [NSString stringWithFormat: @ "% @", [[[deviceToken description] identifier: @ "<" withString: @ ""] stringByReplacingOccurrencesOfString: @ ">" withString: @ ""] stringByReplacingOccurrencesOfString: @ "withString: @" "]; // register token [UMessage registerDeviceToken: deviceToken];}

3. Receive and push

-(Void) application :( UIApplication *) application didReceiveRemoteNotification :( NSDictionary *) userInfo {// values sent from notifications pushed by the server are all in userinfo. [UMessage didReceiveRemoteNotification: userInfo]; [UIApplication sharedApplication]. applicationIconBadgeNumber = 5; if ([[UIDevice currentDevice] systemVersion] floatValue]> = 8.0) {UIUserNotificationType myType = custom | custom; UIUserNotificationSettings * mySetting = [UIUserNotificationSettings settingsForTypes: myType categories: nil]; [[UIApplication sharedApplication] registerUserNotificationSettings: mySetting];} else {UIRemoteNotificationType myType = External | external; [[UIApplication sharedApplication] external: myType];}

  4. Manage the background test and send the push manually. ()

Next let's talk about Step 4: add the test device. Because I am using the developer mode, we need

The test is added by the TOKEN. The method for obtaining the TOKEN is the previous step (2. register the device Token, the first line of code)

 

 

The server servlet implementation will be added tomorrow.

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: info-contact@alibabacloud.com 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.