- 1. Create Apple ID in Apple Developer Website
- 2. Check on "Push Notification" in the functionality
- 3. Configure for Push Notification in Development:create certificate
- 3.1 Upload the certificate file which is generated by keychain access.
- How to generating the Certificate Signing Request (CSR):
- 3.1.1 Keychain access, Certificate Assistant, request a CE Rtificate from a certificate Authority
- 3.1.2 Save the certificate file to the disk as "your Name.certsigningre Quest ", which is used to be uploaded.
- 3.2 Download SSL Certificate and save as "Aps_development.cer"
- 3.3 Click the "Aps_deve Lopment.cer "To install, you'll see it in keychain access, export as. p12 file
- 3.4 Use command line to TRANSFO RM it from. P12 to. PEM, which is used in the server. Keep in mind for the password, which would also be used in the server
- $ OpenSSL pkcs12-in cert.p12-out apple_push_notification.pem-nodes-clcerts
- 4. Create provision file for the Apple id:generate and drag it to Xcode
In APPDELEGATE.M, implement the methods below:
---------------------------------------------#pragma mark-app delegate//-------------------------------------- --------(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (Nsdictionary *) launchoptions {//Override point for customization after application launch. ---------------------------------------------//SET push notification//---------------------------------------- -----if ([Application respondstoselector: @selector (isregisteredforremotenotifications)]) {//IOS 8 Notifica tions [Application registerusernotificationsettings:[uiusernotificationsettings settingsForTypes: ( Uiusernotificationtypesound | Uiusernotificationtypealert | Uiusernotificationtypebadge) Categories:nil]; [Application registerforremotenotifications]; } else {//IOS < 8 notifications [application Registerforremotenotificationtypes: (Uiremot Enotificationtypebadge | Uiremotenotificationtypealert| Uiremotenotificationtypesound)]; }//---------------------------------------------//accept push notification when app isn't open//--------- ------------------------------------nsdictionary *remotenotification = [launchoptions objectforkey: Uiapplicationlaunchoptionsremotenotificationkey]; if (remotenotification) {//[self handleremotenotification:application userinfo:remotenotif]; } else{//Do nothing. } return YES;
---------------------------------------------#pragma mark-push notifications delegate//------------------------ ----------------------(void) application: (uiapplication*) application Didregisterforremotenotificationswithdevicetoken: (nsdata*) devicetoken{NSLog (@ "This device token is:%@", Devicetoken); NSString *token = [[[[Devicetoken description] Stringbyreplacingoccurrencesofstring: @ "<" withs Tring: @ ""] stringbyreplacingoccurrencesofstring: @ ">" withstring: @ ""] St Ringbyreplacingoccurrencesofstring: @ "" Withstring: @ ""; Call the server function to register this device//...} -(void) application: (uiapplication*) Application Didfailtoregisterforremotenotificationswitherror: (NSError*) error {NSLog (@ "Failed to get token, error:%@", error);} -(void) Application: (UIApplication *) application didreceiveremotenotification: (nsdictionary *) userInfo{NSLog (@ " Didreceiveremotenotification "); Uiapplicationstate applicationstate = application.applicationstate; if (applicationstate = = uiapplicationstateactive) {//app is already in the foreground NSLog (@ "Content:% @ ", [[UserInfo Objectforkey: @" APS "] Objectforkey: @" alert "]); Uiremotenotificationtype enabledtypes = [[UIApplication sharedapplication] enabledremotenotificationtypes]; if (Enabledtypes & Uiremotenotificationtypebadge) {//badge number is enabled} if (enabledty PES & Uiremotenotificationtypesound) {//sound is enabled} if (Enabledtypes & Uiremoteno Tificationtypealert) {//alert msg is enabled}} else{//app were just brought from BACKGR Ound to Foreground}}
- Server Side (Ruby on Rails):
Gem Recomend:https://github.com/nomad/houston
[1]http://www.raywenderlich.com/32960/apple-push-notification-services-in-ios-6-tutorial-part-1
[2]https://www.youtube.com/watch?v=_3ylqwwni6s
IOS 8 Apple Push Notification Service