"IOS push notification": from creation to setup to running

Source: Internet
Author: User
Tags key string ssl certificate

Abstract:This is a compiled article (because I rarely write purely translated articles myself). The content and dairy products are all from the iOS development tutorial of parse.com. At the same time, the author also provides video explanations, developers who are willing to contact the listener can check the video (don't tell me that the video cannot be viewed ). This article will take developers step by step to explore the depth of IOS push notifications and learn how to configure IOS push notifications. A little background information...

This is a compilation article. The content is from the iOS development tutorial of parse.com, and the author also provides video explanations. This article will take developers step by step to explore the depth of IOS push notifications and learn how to configure IOS push notifications.

Brief background information

As we all know, using push notifications is a great way to add real-time message notifications to applications. In this way, developers and users will always maintain a pleasant and close relationship with each other.

However, unfortunately, IOS push notifications are not so easy to handle. Developers are often exhausted, frustrated, and unable to last. Now, the savior is here! As long as you read this tutorial, you will be able to get rid of these troubles and become a dynamic and vigorous (robust I mean !) Developers.

Preparations before the official start

Create an SSL Certificate associated with the app ID and the development and supply configuration file from the apple developer website to start this wonderful tutorial. Next, let's take a look at how to configure the parse app on the parsing website (PARSE website) in IOS. Finally, we put these theories into practice, create an app with the push function, and push messages to users.

Before starting this wonderful journey, you must note that the IOS simulator does not support pushing, so you must find a real machine. There is also the need for Apple developer protocols before development and testing can be performed on the real machine.

Create an SSL Certificate

First, you need to create an app ID and the associated SSL certificate on the Apple developer website. With this certificate, the resolution server can find your app ID, then, push the notification to the application.

Create a certificate request

First, we need a certificate signature request file before creating an SSL certificate. The method for creating a file is as follows:

1. Run keychain on Mac)

2. select key string access> certificate assistant> request a certificate from the Certificate Authority

3. enter your name and email address. The ca email address can be changed by default.

4. Select "Save to hard disk" to download the certificate request file you just created to the desktop.

Create and assign an app ID

Each IOS program installed on your developer device requires a unique app ID. For convenience, the app ID is named by reverse path rules, such as COM. parsesampleapp, but be sure that the app ID cannot contain an asterisk ("*"). The procedure is as follows:

1. log onto the website Apple developer member center and go to the IOS provisioning portal.

2. Click app IDs from the Left bar.

3. Select the new app ID and create a new app ID. Make sure that the bundle identifier column does not contain an asterisk.

4. Find configure under your app ID and select.

5. Check "enable for Apple push notification service" and click Configure under "Development push SSL certificate". The "Apple push notification service SSL Certificate assistant setting wizard appears.

6. Click continue to continue, and then click choose file to select the. certsigningrequest file you just created.

7. Click Generate to start generating, and then click Download to download the generated SSL certificate.

8. Install the downloaded SSL certificate through the keychain program.

9. In the "my certificates" option, find the certificate with the name you just installed, such as "Apple development IOS push services: XXX.

10. Double-click the certificate and select "Export". The exported file suffix is. p12. Pay attention to this time! Do not add anything when a password prompt appears.

It is worth noting that, at this point, we have only enabled the push notification function of the application in the development mode, so before the application is officially released, remember to repeat the process from step 4 to Step 9, and change "Development push SSL Certificate" in step 5 to "production push SSL certificate ". This is perfect.

Create a provisioning Profile)

Provisioning profile verifies the device that runs the developed application. Whether you create an app ID or modify the existing one, you must re-Generate and install the provisioning profile again. The procedure is as follows:

1. Select provisioning change in the IOS provisioning portal.

2. Click new profile.

3. Fill in the corresponding information and make sure that none of the three items (developer certificate, the created app ID and the device used for testing) are missed. All items are selected.

4. Click the Download button under the actions column to download the generated provisioning profile.

5. Double-click the downloaded file, which is enabled by the iPhone Configuration Utility Program by default.

Configure the parse app

To use the parse function in push notifications, you must set this feature to enabled and upload the push SSL Certificate created above. The procedure is as follows:

1. Find your parse app on parse website and select the settings tab.

2. Under IOS push notification settings, click choose file and upload the. p12 file exported with keychain.

3. If you want the user to be able to send push notifications, do we need to push the client to enabled? Select Yes. This function is very useful for software like instant chat. Now we select it. Of course, developers need to decide whether to enable this function.

4. Click Save to save.

So far, all the prerequisites have been completed, and the most exciting step is to create a push notification application.

Create an application with push notifications

First, we need to set the xcode project to make sure that the app ID and provisioning profile are both set to a good state. Development,

1. Select the ProjectName-Info.plist under the supporting Files folder and modify the bundle identifier option in the right view, which is consistent with the app ID you created (such as com. parsesampleapp ).

2. Select the project file you just created from the menu on the left, find build settings below, and search for code signing identity.

3. Set all values of the corresponding provisioning profile.

4. Select the project name under targets on the left side, find build settings again, and go to the code signing identity area to ensure that all values are consistent with the new provisioning profile.

Code stage

Next we start to enter the programming mode. We need to make a few changes to the app proxy so that our app can receive push notifications. The procedure is as follows:

1. To register a device, you must call the [Application registerforremotenotificationtypes:] Method in the [Application: didfinishlaunchingwitexceptions:] Method of APP delegate. The Code is as follows:

  1. - (BOOL)application:(UIApplication *)application 
  2.  didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
  3.     ... 
  4.     // Register for push notifications 
  5.     [application registerForRemoteNotificationTypes:  
  6.                                  UIRemoteNotificationTypeBadge | 
  7.                                  UIRemoteNotificationTypeAlert |              
  8.                                  UIRemoteNotificationTypeSound]; 
  9.     ... 

2. Once successful, the above method will execute the callback method [Application: didregisterforremotenotificationswithdevicetoken:] in APP delegate.
. We need to implement this method to inform parse of our device information. The Code is as follows:

  1. - (void)application:(UIApplication *)application  
  2. didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)newDeviceToken 
  3.     [PFPush storeDeviceToken:newDeviceToken]; // Send parse the device token 
  4.     // Subscribe this user to the broadcast channel, ""  
  5.     [PFPush subscribeToChannelInBackground:@"" block:^(BOOL succeeded, NSError *error) { 
  6.         if (succeeded) { 
  7.             NSLog(@"Successfully subscribed to the broadcast channel."); 
  8.         } else { 
  9.             NSLog(@"Failed to subscribe to the broadcast channel."); 
  10.         } 
  11.     }]; 

3. broadcast channels are used to contact all users at the same time. Therefore, developers may need to create more precise channels themselves. Once the push notification is accepted but the application is not in the foreground, it will be displayed in the IOS push center. Otherwise, if the application is active, it is handed over to the application for processing. Specifically, we can implement the [Application: didreceiveremotenotification] Method in APP delegate. The following sample code simply submits this requirement to parse for processing. parse creates a modal alarm to display the push content.

  1. - (void)application:(UIApplication *)application  
  2. didReceiveRemoteNotification:(NSDictionary *)userInfo { 
  3.     [PFPush handlePush:userInfo]; 

Now, you can start running on your iOS device. If everything goes well, you can see a modal alarm request license from the user to the push notification.

Send push notification

Send from parse website

Parse allows you to send push notifications from parse website, both API and SDK. Find the parse app and select the push notifications tab. You can add a message in the text box and broadcast it to the user. You can use the parse web API to send a POST request to any channel. The following example shows a broadcast notification with the content "Hello World", which is sent using curl.

  1. curl -X POST "https://api.parse.com/1/push" -H "Content-Type: application/json" \ 
  2. --data '{"key":"your_push_master_key", "channel":"", "type":"ios",\ 
  3. "data":{"alert":"Hello World!"}}' 

Send from Application

To send a message from an application, you must enable the client push enabled function in the parse app. You can find everything in the ios api documentation.

  1. // Broadcast "Hello World" 
  2. [PFPush sendPushMessageToChannelInBackground:@"" withMessage:@"Hello World!"]; 

Okay. This is the end of the tutorial. I wish you a smooth development. If you have a good application, contact @ csdn mobile or send an email
Yangpf@csdn.net, recommendations to us.

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.