Using push notifications in the iOS platform enables you to send interactive notifications to your app users. After enabling this feature, the user must agree to receive your messages. The user can also turn this feature off at any time, by going to the device Settings > Notifications. Unlike in Android, you do not have any control on the visualisation of the message, but you do have the Badge feature, which gets the user attention for the unread messages and also gives you the ability to count the number of the unread message.
- Configure your app in the Apple Developer Provisioning Portal.
- Add push notification support to your app.
- Configure your app in the PushApps Admin Console.
- Integrate the PushApps SDK into your app.
Push notifications will not work on an emulator, you must try them on a real device
Configure your app in the Apple Developer Provisioning Portal
- Login to the Apple Provisioning Portal.
- Go to the Certificates, Identifiers and Profiles section and choose Identifiers.
- Make sure you are on the App IDs section and press the "+" sign in order to add new application.
- Fill a name and a bundle id, and at the bottom of the page, in the App Services, choose to enable Push Notifications. After that, please press Continue.
- Confirm the details of the app and press Submit:
- After pressing DONE, you'll see you're new app in the list. Congrats.
Add push notification support to your app
- Go to the Identifiers section, and choose your app from that list.
- Press on the Edit button and make sure that the Push Notification service is enabled (checkbox should be checked).
To enable push notification in your app, you'll need to create a certificate, protected with password, in order to communicate with Apple's servers. As you can see from the above screenshot, there are two environments to configure: one for development and testing (also known as Sandbox) and one for production. It is not MUST to create a development certificate, but if you want to be able to test your app before uploading it to the AppStore, it is recommended to create one.
In this tutorial we will create a development certificate, in order to test it later with the PushApps SDK. The creation of the production certificate is the same.
- Press on the Create Certificate...
- As you can read from the Apple explanation, you are now requested to generate a CSR file (Certificate Signing Request). Go to your Mac Launch Pad and search for "Keychain Access". Press on it's icon. From the Keychain Access menu, hover on the Certificate Assistant and choose Request a Certificate From a Certificate Authority.
- Inside the dialog, you can leave the User Email Address as is and give it a Common Name, so you can identify it later. Choose Saved to disk and press continue. Afterwards, save the file to disk and press Done.
- Back to Apple Developer Portal (from step 4) - press Continue and then Choose File... Select the CSR file we've created.
- Press Generate and your certificate is ready!
Download the file and open it. You should see the Keychain Access app opened again, and your downloaded certificate in the My Certificates list.
Notice: you can identify between your development and production certificates, in your Keychain Access. The prefix of your push notification certificate should be "Apple Development iOS Push Services" for the development certificate and "Apple Production iOS Push Services" for the production certificate. See also in the screenshot above.
Configure your app in the PushApps Admin Console
- After installing on your Mac the new certificate, we need to generate a p12 file, in order to communicate with the Apple servers. Go to your Keychain Access app, and select your app push notification certificate. If you do not see an arrow on the left of your certificate, it means you do not have the private key, which is needed for the creation of the p12 file. If that's the case for you, please start with the Add push notification support to your app section.
After selecting the proper certificate, right click on the selected row and choose export.
Please do not select both the certificate and the private key (the one with the key sign, below the certificate). If you do so, your p12 file will not be compatible and you will not be able to push messages to your users.
- Give the p12 file a name and choose your password for it. Remember that password, because will use it later. You will also be asked to prompt your mac password.
- Ok. We're set to go to the PushApps Admin Console. Login and go to My Apps, choose the relevant app and go to Settings > Manage Platforms and click on Configure by the iOS icon.
- Upload the p12 file we've created, under the Apple P12 File field. Enter the password you gave the file and select the correct Gateway (for this tutorial it should be Sandbox, but if you're about to upload this version to the AppStore or creating AdHoc version, the Production gateway is the one for you. Press Save. If the password does not match to the file, you'll get be prompted with an error message, so don't worry!
- After pressing Save (and if your password matches the file), you'll see the iOS icon color turning to dark blue. Now we're set to go! Let's integrate the PushApps SDK into your iOS app and start pushing messages!
Integrate the PushApps SDK into your app
For swift instructions, please check our demo project here.
- Download the SDK from the PushApps GITHUB repository.
Add PushApps.framework to your Xcode project. Please make sure that the "Copy items into destination group's folder (if needed)" is NOT checked.
Import <PushApps/PushApps.h> into your AppDelegate.m file and inside the didFinishLaunchingWithOptions method add the startPushAppsWithAppToken method:
Still inside your AppDelegate.m, add the following methods:
- That's it!