"IOS Push full resolution (i)" translation "--ios Push overview

Source: Internet
Author: User
Tags cheap shared hosting hosting vps shared hosting virtual private server

This is a tutorial from Raywenderlich, the content is informative! The structure is simple, the explanation is gradual, the article quality is superior! It's a difficult blog post! Use half a bottle of English to translate a bit:
1. Overview of Push (Ben Boven)
2. Generate a push certificate to generate the provisioning profile
3. A minimalist demo, and test push

View the original text here

--------------------------------------------------------------------------------------------------------------- ---------------------------------------------------------------------

In iOS, apps can't do too much in the background and are only allowed to do a limited amount of activity so that battery life is protected. However, if some interesting time occurs, and you want to let the user know, even the user is not using the app.

For example, users receive a new microblog, their favorite team wins the game, or their supper is ready, and since the app is not running, the app cannot detect these events.
Fortunately, Apple has a solution for these issues. Developers can write a server-side build, replacing the client's constant detection or working in the background.

When an event of interest occurs, the server-side build can send a push notification to the app;

Push notifications can do the following three things:

Display a short text message
Play a sound

Set the number of badge in the app icon


< Learn how to add push notifications to your app >
Developers can combine these features, such as playing a sound, and setting badge numbers, but not displaying text messages.

With this series of articles, you will implement a simple app and use push notifications yourself. In this part of the article, you will learn how to configure your app to accept push notifications and send a test message.

This tutorial is for advanced iOS development, and if you're still new to iOS, you should look at other tutorials. It is also highly recommended that you take a look at the following two tutorials

How to Write A simple php/mysql Web Service for IOS App
How to Write A IOS App that Uses A Web Service
Cut the crap, let's get started.
Getting Started:brief Overview

Push push notifications to the app to do quite a lot of work is a multi-party jigsaw puzzle:


(Push works schematic)
1. An app enables push notifications. Users have to confirm that they will receive these notifications.
2. The App receives a "device token" and you can assume that device token is an address and the push notification will be sent here.
3. The app sends the device token to your app's server.
4. When an interesting event occurs, the app's server sends a push notification to Apple push Notification Service (abbreviated as APNS)
5. APNs sends a push notification to the user's device.
When the user device receives a push notification, an alert appears on the device, playing a sound or updating the app's icon. Users can activate the app via alert and give the push content.
The push notification is also worth it, since we have local notifications and multitasking. Local notifications are limited to time-setting events, and only "VOIP, map navigation, and background playback" can make the app run in the background. If you want to notify users that the app has been close, you'll need a push notification.
In this tutorial, I'll elaborate on the push notification mechanism and how to build push in the app. More content, enjoy it.
What you need to prepare for push notifications in order to add push notifications to your app, you need to:
an iphone or ipad。 Push notifications are not good for the emulator, so you need to test on the real machine.
IOS Developer Program Membership。 You need to create a new app ID and provisioning profile with an SSL certificate (app server use). These are all done in iOS Provisioning potral.
If you want to follow the example in this article, you also need to create your own provisioning profile and SSL certificate; you can't use mine. Because it is important to get a certificate, I will elaborate on the steps to apply for a new certificate.
a server to connect to the network。 Push notifications are always issued by the server. As a developer, you can use your Mac as a server, but as a product release, you need at least one thing similar to the VPS (Virtual Private server).
A cheap shared hosting account is not enough, you need to run in the background, install an SSL certificate, and support a specific port for TLS outside connections.
Most of the shared hosting providers don't let you do this. Maybe after you ask, he'll do it. I really recommend using a VPS, like "Linode"
Profiling a push Notification app server is responsible for creating a push message, so it's useful to know what the push message looks like. A push notification is a short message that contains device token,payload and some other bytes. Payload is the real data. The APP server should provide a dictionary in JSON format. The payload of a simple push message looks like this:
{"APS": {"alert": "Hello, world!", "Sound": "Default"}}

A pair of {} contains a dictionary. Payload is a dictionary that contains at least one "APS", in the example above, APS contains two fields alert and sound. The client receives this push notification, displays an alert text "HelloWorld" and plays the standard effect sound.
You can also add other items to the APS, such as:
{"APS": {"alert": {"Action-loc-key": "Open", "Body": "Hello, world!"}, "badge": 2}}

Now alert is a dictionary. "Action-loc-key" provides selectable text. The badge field contains the numbers displayed on the app icon. The push does not play a sound.
The JSON-formatted payload is configured in many configurations. Open can change the sound of playback, you can provide localized text, you can customize the Add field. Click here to see more local and Push Notification Programming Guide.

The push notification itself should be short for the purpose, payload maximum is 256bytes, and the same size as SMS and Weibo. The smart push server does not waste space and line breaks, and the resulting push message looks like this:
{"APS": {"alert": "Hello, world!", "Sound": "Default"}}

It's not easy to read, but it saves bytes. Payload more than 256 of push notifications will not be accepted by APNs.
Issues with Push notifications It's not reliable .。 No one is sure that the push notifications will be distributed accurately, even if the APNS server accepts them. As APP server is concerned, the push notification is fire-and-forget. There is no way to know the status of the push message sent to APNs. The distribution of time is also very different, maybe a second level may be half an hour.

In addition, the iphone user may have not enabled the push notification feature, possibly in a wifi environment, the WiFi environment blocked the port of APNs, the iphone may have been turned off. APNs will try to send the last notification when the phone comes back online. But APNs will only try a certain number of times, more than that. This push message is lost forever.


(push is not reliable)
It might be expensive .。 It's easy and inexpensive to add push functionality to your app. Push notifications become expensive under large user volume. For example: You notify your users when the RSS changes. Because you control the RSS and know when it changes. When you update on the website, the server sends a notification. However, if your app is an RSS feed, allow users to put their own URLs in. In this case, you need to come up with some mechanism to detect and update the data.
In practice, your server needs to keep track of the feeds of these changes. If you have a large number of users, you may need to expand your server and broadband. This makes push notifications expensive and not worth it.

The theoretical knowledge is almost over, start learning how to do push notification. Before we get started, we need to do some annoying setup work on iOS provisioning portal.

Hard goods is the next article http://blog.csdn.net/hherima/article/details/45583865

"IOS Push full resolution (i)" translation "--ios Push overview

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.