Push Notification helps you in sending event or alert to your app users even when they are not logged into app. App42 uses APNS (Apple Push Notification Service) to send Push Notification on iOS devices. To configure Push Notifications for iOS Apps/Games, the prerequisites are :
An iOS Developer Program membership on iOS Dev Center
A Server, and this is where App42 Push Service comes into the picture.
Once you have all, you need to generate AppID and SSL certificate on iOS Developer portal, .p12 file and a provisioning profile configured for push notification. This guide will walk you through all the necessary steps needed to configure your app for push notification.
To manually generate the certificate, Certificate Signing Request (CSR) file is needed from your MAC that will be used to authenticate the creation of SSL certificate. To create CSR file, please follow the steps mentioned below:
Open Keychain Access(Applications->Utilities->Keychain Access)
Choose the menu option “Keychain Access -> Certificate Assistant -> Request a Certificate From a Certificate Authority…” and make sure no private key is selected in the main Keychain Access window.
Enter your Email Address and Common Name and check Saved to disk and click Continue to save it to your prefered location.
To install an application on your device, you need to create an App ID and you do this on iOS Dev Center .
Login and select Certificates, Identifiers & Profiles .
Select Identifiers in the presented screen :
Click on the + button at the upper right corner of the presented screen:
Enter the name for new AppID under App ID Description.
Select App ID Prefix.
Select Explicit App ID option under App ID Suffix and enter the Bundle ID.
Enable Push Notification for this App ID by selecting the checkbox next to Push Notifications under App Services.
Select Continue and Confirm all the details are correct in the presented screen such as App ID description, Bundle Identifier and Push Notifications Checkbox and Select Submit button to finish the App ID creation.
Now we will generate SSL certificate that is needed to make a secure connection between the App42 Push Server and APNS. This certificate will be linked to the App ID you just created so that the App42 Server will send push notifications to this particular app only.
Select App IDs under Identifiers that shows list of app ids and select your newly created App ID i.e. App42PushApp.
Select Edit button in the presented screen.
Scroll down to Push Notifications to create SSL certificate.
Select Create Certificate under Development SSL Certificate as we are creating for development environment.
Next you will be guided to Add iOS Certificate screen where you will be asked to create Certificate Signing Request(CSR) that we have created already under Section-1 and hence Select Continue.
Next you will be asked to upload the CSR file. Select the Choose File and browse to .certSigningRequest file and Click Open then Click Generate to generate the SSL certificate.
It may take few seconds to generate the certificate. Once generated, click Download to download the certificate. I recommend to store all the generated files in the single folder as it will be easy to locate the files later.
Now you have a valid certificate for sending push notification in development environment, If you need this for Production environment, repeat the same process for the Production.
Now locate the SSL certificate file that you just downloaded and double click to install it to your Keychain Access.
Now Open Keychain Access -> My Certificates(Under Category section)and Right Click on the certificate you just installed and choose Export.
Enter the filename and select the location to save and click Save.
Enter the export Password when asked. You may be asked to enter your system account password to allow Keychain Access to export the certificate from your Keychain.
Make your .p12 file compatible with APP42 server by following the below mentioned steps:
a. Keep your .cer file and .p12 file in a single folder
b. Open terminal and go to the folder that has both the files $ cd “your folder path”
c. Now execute the following commands in the terminal :
openssl x509 -in aps_development.cer -inform DER -out developer_identity.pem -outform PEM openssl pkcs12 -nocerts -in App42PushDevKey.p12 -out App42PushDevKey.pem openssl pkcs12 -export -inkey App42PushDevKey.pem -in developer_identity.pem -out iphone_dev.p12
Where, aps_development.cer <= SSL Certificate you downloaded from Apple in Step 3 and App42PushDevKey.p12 <= The .p12 file you just created above.
Go to iOS Dev Center and select Certificates, Identifiers & Profiles . Select Provisioning Profile option from the sidebar and select + button.
Now you have to follow a 4-step Add iOS Provisioning Profile wizard
Step-1 : Select Type
Select iOS App Development under Development and then click Continue.
Step-2 : Configure
Select the App ID you created earlier in section-2 of this tutorial for me it is “App42PushApp” and click Continue.
Step-2.1 Select Certificates :
Select the certificates from the list provided to include in this provisional profile and click Continue.
Step-2.2 Select Devices :
Select the devices you wish to include in this provisioning profile and click Continue.
Step-3 : Generate
Enter a meaningful name for this provisioning profile in field Profile Name.This will be used to identify the profile in the portal. Now click Generate.
Step-4 : Download
Select Download to download the generated profile. Add the profile to Xcode by double clicking on it and You are done.
Note:- Repeat the process to generate the Ad Hoc / App Store profile, the only difference is, select the Select Type as Ad Hoc / App Store instead of Development in the Step-1.
To send Push Notification using App42 Cloud API, you have to upload the iphone_dev.p12 file, that you created in step-4, to AppHQ Console.
Register with App42 platform
Create an app once you are on Quick-start page after registration.
If you are already registered, login to AppHQ console , create an app from App Manager -> App Create link and select Push Notification in AppHQ Menu.
Select iOS settings in Settings.
Select your App Name from the drop down menu.
Browse your iphone_dev.p12 file by clicking ‘choose file’ option to upload the file.
Enter password given during creation of the iphone_dev.p12 file.
Select the development environment from the drop down menu.
Click on the submit button and it’s done here.
Repeat the same process to configure App42 Cloud API App for Push when it is ready for distribution, except selecting production environment for Environment option from the drop down menu.
Note:- Environment drop-down menu has two options development and production. You can upload two .p12 files one for each environment. But we recommend to have only one active push profile at a time.
In the Object Inspector, set the following properties of the App42Provider:
Expand the Android Push node and copy to GCMAppID the Project Number from above step.
Set UserName for the user
On the form, select PushEvent1 and go to the Object Inspector.
Check whether the Provider property is set to App42Provider1
Switch to Code tab by pressing F12.
Define the event handlers as follows:
implementation procedure TForm1.PushEvents1DeviceRegistered(Sender: TObject); begin Memo1.Lines.Add('Device Registered'); Memo1.Lines.Add(''); end; procedure TForm1.PushEvents1DeviceTokenReceived(Sender: TObject); begin Memo1.Lines.Add('Device Token Received'); Memo1.Lines.Add(''); end; procedure TForm1.PushEvents1DeviceTokenRequestFailed(Sender: TObject; const AErrorMessage: string); begin Memo1.Lines.Add('Device Token Request Failed'); Memo1.Lines.Add(AErrorMessage); Memo1.Lines.Add(''); end; procedure TForm1.PushEvents1PushReceived(Sender: TObject; const AData: TPushData); begin Memo1.Lines.Add('Device push received'); Memo1.Lines.Add(AData.Message); Memo1.Lines.Add(''); end; end.
Your application will need OpenSSL support in order to make HTTPS requests. On platforms that do not include OpenSSL libraries, such as iOS, you will need to download OpenSSL libraries. For iOS devices you need to download the libcrypto.a and libssl.a static libraries. The location of downloaded libraries is important. For static libraries, the files need to be in the linker library path or in the project directory.
Right-click your project in the Project Manager. Choose Project > Options > Entitlement List, and select Receive Push Notification in iOS.
Choose Project > Options > Version Info, and set the CFBundleIdentifier key. This should be the same as the identifier of your App ID.
Now your application is ready to run on either a simulator or your connected mobile device. To run your application
In Project Manager, select your target platform.
Choose either of the following commands: Run > Run /(OR) Run > Run Without Debugging
Click the Active checkbox.
Sending Push Notification:
The push notification can be sent from the AppHQ console.
To send Push messages from AppHQ Console, Login to AppHQ Console and select Users under Push Notification in AppHQ Menu.
Select your App42 App name from drop down menu under Users section.
Select the user name to whom you want to send Push message.
Click Send Push.
Type your message in the Message section in the Send Push window and Click Send and you are done.
For the detail delivery reports you can see the Push Logs by selecting Push Logs option from the left-side menu and then the respective App42 App from the drop down under Push Logs.
You can also send push messages to All your users by selecting Send Push To All instead of Send Push.