Twilio Notifications starter iOS application in ObjC
This application should give you a ready-made starting point for writing your own notification-integrated apps with Twilio Notifications. Before we begin, you need to collected the credentials to run the notifications web app.
Credential | Description |
---|---|
Twilio Account SID | Your main Twilio account identifier - find it on your dashboard. |
Twilio Credential SID | Adds notification ability to your app - generate one here. You'll need to provision your APN push credentials to generate this. See this guide on how to do that. |
Twilio Notification URL | The base URL for the Notifications API -- https://notification.twilio.com |
Twilio Notification_Service SID | Use the create_service.js script to generate this. Just run 'node create_service.js' in your terminal. |
You can download the Node notifications web app from here.
##Setting up the web app
Edit config.json
with the four configuration parameters we gathered from above.
Next, we need to install our dependencies from npm:
npm install
Now we should be all set! Run the application using the npm
command.
npm start
Your application should now be running at http://localhost:3000.
##Please Note You'll need to test this on the device, since the iOS simulator can't receive notifications. To test on device, your server will need to be on the public Internet. For this, you might consider using a solution like ngrok.
After downloading or cloning the app, in a terminal window enter the following
'pod install'
This will install the necessary dependency (AFNetworking). Once it's installed you can go ahead and open 'notification.xcworkspace'.
In the ViewController file, on this line,
static NSString * serverURL = @"http://YOUR_WEB_APP/register";
Replace the URL with the address of your server. The app uses 4 credentials to register your device for notifications.
Credential | Description |
---|---|
Identity | This is how the web app identifies an individual user as the receiver of notifications. |
Endpoint | This is a unique device ID and identity combination that can receive a message. (i.e Alice on her iPad is a different notification destination than Alice on her iPhone). |
Bindingtype | This lets the web app know which service to register with (APNS or GCM). |
Address | This is the unique device identifier of the mobile client. |
Once you've entered your URL, you can compile & run the app. Enter in an identity in the text field that's presented. Once you tap register, the app will register your device with APNS and return a JSON response object if successful. After that, run the notify.js script in the web app repo
node notify.js YOUR_IDENTITY
To receive a notification in your app.
That's it!
MIT