IPhoneWrite an applicationPush Notification ServerThe client sends notifications as described in this article.Push notificationAfter obtaining the device token from the device token, you must send the token string to the application'sServerEnd, that is, provider.
The provider sends the token number, notification content, and notification form (for example, whether a prompt window is displayed or whether a voice is voiced) to the apns server of apple ).
The simplest provider implementation is to establish a secure connection (tsl or ssl) with the Apple Server through a certificate. After a connection is established through authentication, the server sends data streams meeting Apple's requirements.
Obtain certificate
Apple provides two access methods:
Developer for testing
Production, used for products
For internal testing, use developer.
Download the certificate through the ios provisioning portal:
This requirement:
The logon apple developer program account must be the highest-level agent. This is for enterprise accounts. If it is a personal account, it doesn't matter.) The agent account is the initial account; otherwise, the configure link cannot be found;
The developer and product must be enabled after the configure operation.
Go to the configure link and click download:
Process Certificate
If you are writing an objc program running on a mac, skip this step without processing the certificate.
If it is used in java, You need to merge and export the private key used for the certificate and the certificate supporting the notification mentioned above, not the iphone developer certificate.
Generate a certificate:
When you click storage, a file Password is prompted:
Of course, the password can be blank.
The following message is displayed:
Enter the password of the mac logon user.
File generation.
Write an instance for sending a notification
For mac code writing, there is a ready-made project available: http://stefan.hafeneger.name/download/PushMeBabySource.zip
To import to xcode, you only need:
Set deviceToken to the token string of the device. In addition, change pathForResource:
- aps_developer_identity
In addition, copy the certificate downloaded in the obtained certificate step to the xcode project Resources directory:
We can see that the file name is consistent with the above pathForResource parameter.
Then run the program to receive the push notification on the device.
If it is written in java, you can use a third-party library, see:
Http://code.google.com/p/javapns/
Write a simple notification sending code:
- Import org. json. JSONException;
-
- Import javapns. back. PushNotificationManager;
- Import javapns. back. SSLConnectionHelper;
- Import javapns. data. Device;
- Import javapns. data. PayLoad;
-
- Public class Main {
-
- /**
- * @ Param args
- * @ Throws Exception
- */
- Public static void main (String [] args) throws Exception {
- PayLoad simplePayLoad = new PayLoad ();
- // Get PushNotification Instance
- PushNotificationManager pushManager = PushNotificationManager. getInstance ();
- // Link the iPhone's UDID (64-char device token) to a stringName
- PushManager. addDevice (& quot; iPhone & quot;, & quot; 00000000 00000000 00000000 00000000 00000000 00000000 00000000 & quot ;);
- SimplePayLoad. addAlert (& quot; My alert message Test & quot ;);
- SimplePayLoad. addBadge (1 );
- SimplePayLoad. addSound (& quot; default & quot ;);
- Device client = PushNotificationManager. getInstance (). getDevice (& quot; iPhone & quot ;);
- PushNotificationManager. getInstance (). initializeConnection (& quot; gateway.sandbox.push.apple.com & quot ;,
- 2195, & quot;/home/ubuntu/mypush. p12 & quot;, & quot; password & quot;, SSLConnectionHelper. KEYSTORE_TYPE_PKCS12 );
- PushNotificationManager. getInstance (). sendNotification (client, simplePayLoad );
No Chinese characters in the test are garbled.
Compile a complex example to control whether a notification has a prompt window or a reminder sound ):
APayload. addBadge (2), number displayed on the mobile app icon
APayload. addAlert (& quot; software version updates & quot;). The prompt text is displayed.
APayload.addSound("default.wav & quot;) to specify the sound.
You can also use a third-party php implementation, for example:
Http://code.google.com/p/php-apns
The basic principle is to start a php service and monitor the memcacheq queue. If there is a message, it is sent to the Apple Server.
Summary:IPhoneWrite an applicationPush Notification ServerThis article is helpful to you.