unsplash

iOS: send push notifications with Firebase

Sikandar Khan
4 min readDec 12, 2018

I am currently learning【Swift 4】 to expand my programming knowledge. I looked at Swift a few years ago, but am now ready to dive into it.

I have programmed for many years with Java, and have some familiarity with Python. So, my approach to learning a new language is influenced by that previous knowledge.

☞ Step1: Create an empty project on XCode

a. Choose `Single View App`

Create New App

b. Make sure you provide a unique package name.

Configure your application

c. Enable capabilities Remote notifications & Push notifications
Click on .xcodeproj -> Capabilities -> Enable Push Notification

☞ Step2: Install requirements using Pod

Requirements such as Firebase & FirebaseMessaging. Before installing make sure that your machine is installed with Cocoapods. If not installed, no worries it is easy to install from here.

// open terminal and run below command
$ cd /your-project-directory/
//Use this command to initialise the pods
$ pod init
Post this command Podfile will be creating in project root directory//Use vi or vim editor(whatever is installed on your machine)
$ vim Podfile
//proceed to install added Pods
$ pod install

☞ Step3: Setup firebase account

a. Create project from here

b. Enter into your created project from the firebase console. Choose the application environment, Android/iOS/Web. Make sure your package name (or bundleId) is same as you entered while setting up XCode application.

c. Add config file(generates from the above process) to project root directory: GoogleService-Info.plist

☞ Step4: Setup certificates at Apple account

a. Register your app ID from here https://developer.apple.com/account/ios/identifier/bundle/create and in App services section, make sure you tick/select Push notifications checkbox.

b. APN(Apple Push Notifications). To enable push notifications, we need to submit CSR.

Create CSR from the MAC — Keychain Access. Enter required details. Choose “Saved to disk” option while requesting a certificate.

CSR creating

d. In the Apple console, you need to upload this CSR certificate.

uploading CSR

e. After the above step, you will be able to download APN certificate. Open this certificate by double-clicking it. Then choose the Export option, which will be saved .p12 certificate.

☞ Step5: Firebase app configure

firebase console to upload p12 certificate

In the section iOS app configurations>>APN certificates>> Choose development or production certificates(based on your previous setup). Upload p12 certificate by clicking the upload button.

☞Step6: Swift4 coding for Push notification

Here I am attaching firebase official git repo — code snippets. You can directly Copy + Paster complete class. Easy understandable.

☞Step7: Trigger message using NodeJS/Java/Python/Go

Firebase console will be providing the required basic code snippets in different programming languages. Post clicking on Generate new private key you will be able to download serviceAccountKey.json .

Firebase console

Here I am adding the code which I configured with NodeJS environment.

node-server.js

☞Step8: Notifications delivered.

Happy Exploration
Learn – Grow – Glow
Reach me at LinkedIn

--

--

Sikandar Khan

Head of Engineering | Product Management, Strategic Thinking