Apns programming-Ios real Machine Test message push

Source: Internet
Author: User
Tags key string

I. Preparations

1. An Apple device, iPhone, iPad, and iPod with iOS operating system are supported.

2. If you have an apple developer account and need real-machine debugging, it is best to be a paid developer. The subsequent steps will be smoother.

3. a pc is required as the push server. If a Mac OS is used, it will be more convenient.

II. General steps

We need to push the server from the test message, send a message to Apple push Notification Services, and then forward apns to the iOS device to complete the message push process.

Because our test server sends encrypted messages to apns, you need to apply for a certificate.

3. Apply for a certificate

1 The following is the required certificate file

2. The certificate application process is as follows. Some content is reprinted from the network.

2.1 create an SSL Certificate

First, you must create an app ID and an associated SSL certificate. With the certificate, the resolution server can find your app ID and then push the notification to your app.

Create a certificate request file:
A. Run keychain on Mac)
B. select key string access> certificate assistant> request a certificate from the Certificate Authority
C. enter your name and email address. The ca email address can be changed by default.
D. Select "Save to hard disk". The. certsigningrequest file is generated.

2.2 create an app ID:
A. log onto the website Apple developer member center and go to the IOS provisioning portal.
B. Click app IDs on the Left bar.
C. Select the new app ID and create a new app ID. Make sure that the bundle identifier column does not contain an asterisk.
D. Find configure under your app ID and select.
E. 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.
F. Click continue, and then click choose file to select the. certsigningrequest file you just created.
G. Click Generate to start generating, and then click Download to download the generated SSL certificate.
H. Install the downloaded SSL certificate through the keychain program.
I. Next, in the "my certificates" option, find the certificate with the name you just installed, such as "Apple development IOS push services: XXX.
J. 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.

Now the SSL certificate is created.

2. 3. Create provisioning
Profile

The provisioning file is used to authorize the iOS device
A. On the IOS provisioning portal, select provisioning
B. Click new profile.
C. Fill in the profile name, certificate, app ID (the app ID you just created), and devices as required.
D. Download the generated provisioning Profile
E. Double-click to install.

After 2.4 is successful, you can use organizer, as shown in


4. Obtain the devicetoken of the device and use xcode
Create a new project and download it directly.

1. Set main identifier to the previous app ID (which must be modified)

2. Add the following code:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

Add

    NSLog(@"Registering for push notifications...");    [[UIApplication sharedApplication]     registerForRemoteNotificationTypes:     (UIRemoteNotificationTypeAlert |      UIRemoteNotificationTypeBadge |      UIRemoteNotificationTypeSound)];

Add new function

- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {        NSString *str = [NSString                     stringWithFormat:@"Device Token=%@",deviceToken];    NSLog(@"%@",str);    }- (void)application:(UIApplication *)app didFailToRegisterForRemoteNotificationsWithError:(NSError *)err {        NSString *str = [NSString stringWithFormat: @"Error: %@", err];    NSLog(@"%@",str);    }- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {        for (id key in userInfo) {        NSLog(@"key: %@, value: %@", key, [userInfo objectForKey:key]);    }        }

5. Use the "server" to send the PUSH message and download the Code directly.

1. Put the previous certificate. Cer file under resource.



2. Set token and send messages,

6. View Messages on iOS devices

1. Use uialertview to display the application: didreceiveremotenotification: notification received.

VII. Document address

The p12 file in the certificate folder is the file required to build a test server using Java, which is not required on Mac.

Programming Apple push notification services. Good English. You can read this article directly.

Http://www.cnblogs.com/zhw511006/archive/2010/09/01/1815089.html




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.