First, the preparatory work
1 has an iOS for the operating system of Apple devices, iphone,ipad,ipod can.
2 with an Apple developer account, you need a real-computer debug, preferably a paid developer, and the next steps will be smoother.
3 need a PC to do push server, if it is a Mac OS system, it will be more convenient.
Second, understand the approximate steps
We need to push the server from the test message, send a message to Apple push Notification Services, and then APNs forward to the iOS device to complete the message push process.
Due to our test server to APNs, we pass the encrypted message, so we need to request a certificate.
III. Certificate of Application
1 The following are the required certificate files
2 The process of certificate application is as follows, some content is reproduced from network
2.1 Creating an SSL Certificate
First you need to 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. Running keychain Access on Mac (keychain)
B. Select Keychain Access > Certificate Assistant > Request a certificate from a certification authority
C. Enter your name and email address, CA email address By default, do not attempt to make any changes.
D. Select "Save to Hard disk" so that. certsigningrequest files are generated.
2.2 Then create the app ID:
A. Login to the website of Apple Developer Member Center and enter the iOS Provisioning portal.
B. Click App IDs from the left sidebar.
C. Select the new app ID, and then create an app ID. Make sure that there are no asterisks in the bundle identifier column.
D. Locate configure under your App ID and select.
E. Tick "Enable for Apple push Notification Service" and then click Configure under Development Push SSL Certificate, and the Apple push Noti will appear Fication Service SSL Certificate Assistant Setup Wizard.
F. Click Continue to continue, then click Choose File to select the. certsigningrequest file you just created.
G. Click Generate to start the build, 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, locate the certificate you just installed with the name "Apple development IOS Push services:xxx".
J. Double-click the certificate, select Export, and the exported file suffix is. p12. Be careful at this time! Do not add anything when the password prompt appears.
This completes the SSL certificate creation.
2.3. Create Provisioning Profile
The provisioning file is used to authorize iOS devices
A. Select provisioning in the iOS provisioning portal
B. Click New profile
C. Fill in the profile Name,certificate,app ID as required (the APP ID you just created), devices
d. Download the generated provisioning profile
E. Double-click Install.
2.4 After success can be through organizer, see as
Iv. get the Devicetoken of the device, create a new project with Xcode and download it directly
1 set the main identifier to the previous app ID (must be modified)
2 Add the following code
[CPP]View Plaincopyprint?
- -(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (nsdictionary *) launchOptions
Add inside
[CPP]View Plaincopyprint?
- NSLog (@"Registering for push notifications ...");
- [[UIApplication Sharedapplication]
- Registerforremotenotificationtypes:
- (Uiremotenotificationtypealert |
- Uiremotenotificationtypebadge |
- Uiremotenotificationtypesound)];
Add new function
[CPP]View Plaincopyprint?
- -(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]);
- }
- }
V. Send a PUSH message with "server" and download the code directly
1 You need to put the previous certificate. cer file under Resource
2 set token, send message,
Vi. see messages on iOS devices
1 hands-on will application:didreceiveremotenotification: Received notification, with Uialertview display to the interface.
Vii. See the information address
The P12 file in the Certificates folder is the file you need when you build a test server with Java, and you do not need it on your Mac.
Programming Apple Push Notification Services, English well, you can read this article directly
Http://www.cnblogs.com/zhw511006/archive/2010/09/01/1815089.html
From http://blog.csdn.net/xunyn/article/details/8243573
APNs Programming----iOS real-computer test message push