Twilio Push Notification: What is Push notification?
Here we are going to understand Twilio Push Notification.
Overview
Twilio is used for chat,sms,voice calling,video,notifications & fax.
Here, we are talking about Push notification.
Let’s Start
Apple push credentials configured with Twilio Notifications which you can then use to receive notifications in your iOS app.
Steps to be followed for Push Notification:-
- Setup an App ID
- Create a Certificate
- Create a Credential SID for Twilio
STEP : — 1 Setup an App ID
- Login to your apple development account.
- Click on App IDs under identifiers sections.
- Two Options : Existing App ID & New App ID
OPTION : — 1 Existing App ID
- Click on your App IS.
- Click on the edit button of app services popup.
- Check the “Push Notification” option.
- Click on done button.
OPTION : — 2 New App ID
- Click on “+” symbol to add a new App ID.
- Give your app description.
- Give it an App ID that matches to bundle identifier.
- Check “Push Notification” option.
- Click Continue.
- Click submit to create App ID.
STEP : — 2 Create a Certificate
- Xcode -> your application -> Target -> General pane
- Signing section :- check “Automatically manage signing”
If you are receiving provisioning error message, you need to change Bundle ID to Unique ID.
- To do so, go to https://developer.apple.com/account/ios/identifier/bundle/create and give the bundle a new name. Then, enter your new identifier in the Identity section of the General pane:
- Xcode -> Capability -> Push Notification -> ON
- You can verify certificates by Apple developer portal or in keychain.
- Congrats! You just created an Apple Development iOS Push Services certificate.
STEP : 3 Create a Credential For Twilio
- Keychain access -> my certificates -> right click on certificate.
- Choose export
- Save it as cred.p12.
- This is your credential file. We’re going to extract your certificate key and private key from this file. We need these 2 keys to create a Twilio Credential.
Create a Certificate Key
- Run the following command in terminal
- openssl pkcs12 -in cred.p12 -nokeys -out cert.pem -nodes
Create a Private Key
- Run the following command in terminal
- openssl pkcs12 -in cred.p12 -nocerts -out key.pem -nodes
- Then this command to process the RSA key
- openssl rsa -in key.pem -out key.pem
Then you can paste your credentials into the web console to upload them.
- Strip anything outside of “ — — -BEGIN CERTIFICATE — — -” and “ — — -END CERTIFICATE — — -” boundaries and outside of “ — — -BEGIN RSA PRIVATE KEY — — -” and “ — — -END RSA PRIVATE KEY — — -” boundaries before pasting them.
Check the ‘Sandbox’ button if you made a development certificate. Sandbox is synonymous with development mode.
- click save.
- you’ll see a SID appear on the new page. Copy it to your clipboard, you will need it in the next step.
- Congrats, you just made a Twilio Push Credential!
Configure your Twilio Service to use your APNS credentials
Set up Notify Service Instance
- In the console, create a Notify service. Make note of the SID! You will use this later when you start writing code further down.
Set up the Twilio Notify sample iOS app
- Open project in Xcode
- On the General tab,set bundle ID to match the one you used to generate the certificate while configuring iOS Push Notifications.
- to match the one you used to generate the certificate while configuring iOS Push Notifications.
Replace the server URL at the top of the ViewController file with your Twilio Functions subdomain URL.
- Build app in device.
- You can see a simple UI where you can enter an identity for the user.
- Now we can create a Binding between user identity & this device.
Create a Binding for iOS Push Notifications (APNS)
- User Identity can be any unique identifier you choose, like a GUID, or a primary key not personal information such as name or email address.
- In the Twilio Console, navigate to the Twilio Notify Quickstart (Register Bindings) Function that you just created, and leave that web page open while you register with the app.
- That way, you can see logging information from your function.
- In the app enter Identity you choose and click the button Register.
- This action creates a Binding which uniquely identifies a user on a certain device, running your application.
- If the binding request wasn’t successful, you’ll see an error message printed in Xcode’s console by the iOS app.
- Now that we have the Binding, we are ready to send our first Push Notification with Notify.
Send a Push Notification to a device running the Twilio Notify sample iOS app
- To send a notification, you can use the Twilio Notify Quickstart (Send Notification) Twilio Function you just created.
- You can either send an HTTP GET or an HTTP POST request to the function.
- You would send a POST request to the function from your application.
- If you don’t have an easy way to POST request, using GET is fine for testing your app.
- Use the identity you used in the app. Because you registered a binding with Twilio, the server will send your device the ‘Hello’ message as a notification.
You’re all set! From here, you can start building your own application.
Rlogical Techsoft Pvt. Ltd is renowned Mobile App Development Company in India. We offer Android, Hybrid, Native, iPhone application development services across the world.