This walks you through running Uniqush in the cloud (under Docker) and setting up an iOS app to receive messages via APNS (Apple Push Notification Service).
Run Uniqush under Docker
Install Docker components
Config
mkdir -p volumes/uniqush
wget https://git.io/vgSYM -O volumes/uniqush/uniqush-push.conf
Security note: the above config has Uniqush listening on all interfaces, but depending on your setup you probably want to change that to localhost
or something more restrictive.
Docker compose file
Copy and paste this content into docker-compose.yml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
|
Start docker containers
1
|
|
Verify Uniqush is running
Run this curl
command outside of the docker container to verify that Uniqush is responding to HTTP requests:
1 2 |
|
Create APNS certificate
In my case, I already had an app id for my app (com.couchbase.todolite
), but push notifications are not enabled, so I needed to enable them:
Create a new push cert:
Choose the correct app id:
Generate CSR according to instructions in keychain:
This will save a CSR on your file system, and the next wizard step will ask you to upload this CSSR and generate the certificate. Now you can download it:
Double click the downloaded cert and it will be added to your keychain.
This is where I got a bit confused, since I had to also download the cert from the app id section — go to the app id and hit “Edit”, then download the cert and double click it to add to your keychain. (I’m confused because I thought these were the same certs and this second step felt redundant)
Create and use provisioning profile
Go to the Provisioning Profiles / Development section and hit the “+” button:
Choose all certs and all devices, and then give your provisioning profile an easy to remember name.
Download this provisioning profile and double click it to install it.
In xcode under Build Settings, choose this provisioning profile:
Register for push notifications in your app
Add the following code to your didFinishLaunchingWithOptions:
:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
|
And the following callback methods which will be called if remote notification is successful:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
|
and this callback which will be called if it’s not unsuccessful:
1 2 3 4 5 |
|
If you now run this app on a simulator, you can expect an error like Error registering device token. Push notifications will not workError
.
Run the app on a device you should see a popup dialog in the app asking if it’s OK to receive push notifications, and the following log messages in the xcode console:
1 2 |
|
Export APNS keys to .PEM format
Open keychain, select the login
keychain and the My Certificates
category:
- Right click on the certificate (not the private key) “Apple Development Push Services: (your app id)”
- Choose Export “Apple Development Push Services: (your app id)″.
- Save this as
apns-prod-cert.p12
file somewhere you can access it. - When it prompts you for a password, leave it blank (or add one if you want, but this tutorial will assume it was left blank)
- Repeat with the private key (in this case, TodoLite Push Notification Cert) and save it as
apns-prod-key.p12
.
Now they need to be converted from .p12
to .pem
format.
1 2 3 |
|
1 2 3 4 |
|
Remove the PEM passphrase:
1 2 3 |
|
Add PEM files to Uniqush docker container
When you call the Uniqush REST API to add a Push Service Provider, it expects to find the PEM files on it’s local file system. Use the following commands to get these files into the running container in the /tmp
directory:
1 2 3 |
|
Create APNS provider in Uniqush via REST API
1 2 3 4 5 |
|
(Note: I’m using a development cert, but if this was a distribution cert you’d want to use sandbox=false
)
You should get a 200 OK
response with:
1
|
|
Add Uniqush subscriber
Using the cleaned up device token from the previous step 281c87101b029fdb16c8e13439436336116001cebf6519e68edefab523dab1e9
, create a subscriber with the name mytestsubscriber
via:
1 2 3 4 |
|
You should receive a 200 OK
response with:
1
|
|
Push a test message
The moment of truth!
First, you need to either background your app by pressing the home button, or add some code like this so that an alert will be shown if the app is foregrounded.
1 2 3 |
|
You should get a 200 OK
response with:
1 2 |
|
And a push notification on the device!