Image for post
Image for post
unsplash

iOS: send push notifications with Firebase

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.

a. Choose `Single View App`

Image for post
Image for post
Create New App

b. Make sure you provide a unique package name.

Image for post
Image for post
Configure your application

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

Image for post
Image for post

☞ 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
Image for post
Image for post
//proceed to install added Pods
$ pod install

☞ Step3: Setup firebase account

a. Create project from here

Image for post
Image for post

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.

Image for post
Image for post

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.

Image for post
Image for post

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.

Image for post
Image for post
CSR creating

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

Image for post
Image for post
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

Image for post
Image for post
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.

Image for post
Image for post

☞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 .

Image for post
Image for post
Firebase console

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

node-server.js

☞Step8: Notifications delivered.

Image for post
Image for post

Happy Exploration
Learn – Grow – Glow
Reach me at LinkedIn

Written by

CTO || Cloud and Distributed Systems Specialist