• Docs
  • Showcase
  • Community
  • DMCA
Thursday, February 25, 2021
Flutter Website
No Result
View All Result
  • Login
  • Register
Flutter Website
  • Home
  • Categories
    • Flutter App
    • Flutter Examples
    • Flutter Github
    • Flutter News
    • Flutter PDF
    • Flutter Tips & Trick
    • Flutter Tutorial
    • Flutter UI
    • Flutter Video
    • Flutter VS
    • Flutter Wiki
    • Flutter With
  • Flutter
    • Flutter for Mobile
    • Flutter for Web
      • Widget Sample
    • Flutter for Desktop
    • Tools
      • Codemagic
      • Flutter Studio
      • Supernova
  • Showcase
  • Community
  • Advertisement
  • Hire Us
No Result
View All Result
Flutter Website
Home Flutter Tutorial

Firebase Push Notifications: Notify your users

By Arathi Shankri

flutter by flutter
Reading Time: 14min read
462
Firebase push notifications: notify your users
430
SHARES
614
VIEWS
Share on FacebookShare on TwitterShare on LinkedinShare to Whatsapp

Table of Contents

  • USE CASE
  • Android Configurations:
    • Note:
  • iOS Configurations:
  • Flutter configurations
  • Testing notifications
  • Conclusion

After working on mobile app development for the past year, I can summarize that some of the Firebase features such as In-App Messaging, Push notifications, Remote Config are a must-have in any mobile app. Even if you don’t use them right away, I think it’s wiser to plug them in so that you don’t have to make frequent deployments. I haven’t used Remote Config yet, just learned about the feature, and already feel, “Gosh! Wish I had known that before” 🙂

USE CASE

I always wondered about how Twitter notifies me of new tweets or Gmail notifies about a new email via the notifications that sit in the notification tray. I am glad I found the opportunity to learn and implement them. Below I share the steps to implement the feature. As always, it was straightforward on android but intricate on iOS.

Android Configurations:

  1. Complete “Set up Firebase and the FCM SDK” from the url https://firebase.google.com/docs/cloud-messaging/android/client
  2. Add the below lines of code in “androidmanifest.xml”

3. Add the below line in “pubspec.yaml”, make sure you check for the latest plugin version on pub.dev.

firebase_messaging: ^6.0.13

Note:

You cannot test the notifications feature on your simulator/emulator.

iOS Configurations:

The important thing with iOS configuration was to follow each of the steps below including changing swift code on XCode (Step 7, which I totally didn’t expect to do)

  1. Generate a “Certificate Signing Request (CSR)” file
  • Open “Keychain Access” and click on the menu Keychain Access -> Certificate Assistant -> Request a Certificate from a Certificate Authority
  • In the dialog that appears, enter the email-id, choose the option “Saved to disk” and click on “Continue” to save your CSR file into a folder.

Firebase push notifications: notify your users

Generate a “Certificate Signing Request (CSR)” file

2. Register your app id on Apple Developer Account

  • Log in to your apple developer account and register your app id (even if the app is a demo app).
  • Make sure you select “Push Notifications” while completing the registration.
  • Once complete, you will be directed back to the developer resources list page https://developer.apple.com/account/resources/identifiers/list

Apple Developer account -> Certificates, Identifiers & Profiles -> Click on Identifiers -> click on “+” to register your app

Firebase push notifications: notify your users

Make sure you select “Push Notifications” while completing the registration.

3. Create and download iOS certificate

  • Click on “Identifiers” and select the identifier/application that you just created.
  • Scroll down to “Push Notifications” and click on the button “Configure” next to it.
  • On the dialog that appears, you will have an option to create a “Development SSL Certificate” or “Production SSL Certificate”. Click on the appropriate button.
  • In the “Create a new certificate” screen that follows, you will have to upload the certificate signing request from step 1. Click on “Choose File” and upload the CSR file that you downloaded in step 1.
  • Once the certificate is successfully created, click on the “Download” button to download the certificate to your local drive.

Firebase push notifications: notify your users

Create development SSL Certificate

4. Generate .p12 private key

  • Locate the certificate you downloaded in step 3 and double click on the certificate to install the same.
  • Go back to KeyChain Access, select your certificate. The name of the certificate will be “Apple Development IOS Push Services: <app bundle id>”
  • Expand your certificate by clicking on the small “down” arrow next to the certificate name.
  • You will see your team name or developer name row with the value “Private Key” under the “Kind” column. Right-click on that row and click on “Export” to save your private key (file with .p12 extension)
  • You will be asked to enter a password to protect your private key. Complete the process.
  • Remember the location where you saved the file.

5. Add the .p12 file to your firebase iOS app

  • Assuming you have added your iOS app on Firebase and added “GoogleService-Info.plist” under the “Runner” folder on XCode. If not, here is the firebase documentation to achieve the same.
  • Log into your firebase project -> iOS app -> Settings -> Cloud Messaging
  • Scroll down, you will find “iOS app Configuration”. Click on “Upload” under “APNs Certificates”.
  • Upload the “p.12” file that you just saved in the previous step.

Firebase push notifications: notify your users

Add the .p12 file to your firebase iOS app

Since this is a demo app, it’s ok to create and upload the development certificate, but you would create and upload a production certificate for a production app.

5. Podfile changes

  • Go to your “ios” folder in finder and open your “Podfile” in the TextEdit app.
  • Add the following lines of code to your pod file and save. Of course, please look up for the latest versions.
Podfile changes
  • Open a terminal window, cd to your ios folder, and execute the command “pod install”.

6. Enable Push Notifications on your project

  • On VS Code, right click on the “ios” folder and open your project in XCode.
  • Click on the tab “Signing & Capabilities”, click on “+ capability” and add “Push Notifications” to your project/app.

Firebase push notifications: notify your users

Enable Push Notifications on your project

7. “Firebase_messaging” package related changes

  • This is a very important step, I didn’t expect to change a swift file as part of configuring push notifications in iOS and learned it the hard way.
  • While in XCode, there are some plugin-specific changes that have to be done for iOS.
  • Under the “runner” directory, you will find the file “AppDelegate.swift”, click on it to open in the right panel.
  • Add the below code
“AppDelegate.swift” changes

Flutter configurations

  • Flutter has a “firebase_messaging” package that will help your app receive the notifications from the firebase.
  • Add this library to pubspec.yaml and you can start using Firebase API.

Testing notifications

  • At this point, you can test your notifications using the Cloud Messaging Firebase console.
  • Remember, you can test notifications only on a real device not on emulator or simulator.
  • But I wrote a simple flutter app to capture the device token and a cloud function to send a custom notification to the app. I would love to share that with you but in a different article. Stayed tuned for that!

Firebase push notifications: notify your users

Cloud Messaging Firebase console

Conclusion

iOS configuration is always a tough cookie. Especially with Push Notifications, you are relying on your notification server such as Firebase to contact the Apple Notification server that in turn reaches out to your iOS device with the message.

But thanks to all the people who have posted their questions/articles on various resources, I was able to get push notifications working on iOS.

Please don’t forget to “clap” ? to help your fellow programmers find this article easily.

Tags: Flutter Weekly

Related Posts

Flutter ui tip 3: popup card
Flutter Tutorial

Flutter UI Tip 3: Popup Card

513
[4k] pbo dart 22. Operator overriding
Erico Darmawan

[4K] PBO DART 22. Operator Overriding

515
Built-time vs  run-time #shorts
Flutter Explained

Built-Time vs Run-Time #Shorts

514
Staggered animations made simple – flutter simple animations tutorial
Flutter Tutorial

Staggered Animations Made Simple – Flutter Simple Animations Tutorial

523
#askflutter at flutter engage
Flutter Official

#AskFlutter at Flutter Engage

520
Spread operator & null-aware operator on lists, maps and sets in dart
Flutter Explained

Spread operator & Null-aware operator on Lists, Maps and Sets in Dart

518
Next Post
Flutter: creating an iot based app to interact with any home electrical equipment

Flutter: Creating an IoT based app to interact with any home electrical equipment

Flutter live learning? – background tasks in flutter – just chatting

Flutter Live Learning ? - Background Tasks in Flutter - Just Chatting

How to animate items in list using animatedlist in flutter

How To Animate Items In List Using AnimatedList In Flutter

  • Flutter & dart – the complete guide [2020 edition]

    Flutter & Dart – The Complete Guide [2020 Edition]

    2266 shares
    Share 906 Tweet 567
  • The Complete 2020 Flutter Development Bootcamp with Dart

    1987 shares
    Share 795 Tweet 497
  • Flutter & Firebase: Build a Complete App for iOS & Android

    1412 shares
    Share 565 Tweet 353
  • Flutter Bloc & Cubit Tutorial

    1284 shares
    Share 514 Tweet 321
  • 40 Beautiful Flutter UI Themes For Developers

    1061 shares
    Share 424 Tweet 265

Made by Google

Flutter is Google’s portable UI toolkit for building beautiful, natively-compiled applications for mobile, web, and desktop from a single codebase.

Follow us

Recent Post

  • Flutter UI Tip 3: Popup Card
  • Quill marketing site – UI ideas for flutter
  • [4K] PBO DART 22. Operator Overriding
  • Microsoft Outlook iOS app – UI ideas for flutter
  • Built-Time vs Run-Time #Shorts

Popular Post

A background app bar plugin with flutter

A background app bar plugin with flutter

585
A customised flutter textformfield to input international phone number

A customised Flutter TextFormField to input international phone number

983

Review Post

Flutter themeswitcher template in flutter

Flutter ThemeSwitcher Template in Flutter

Congratulations, Nice Work, GLWS $7
Rosen – flutter ecommerce ui

Rosen - Flutter Ecommerce UI

Nice Product I am gonna love it. $18
  • [email protected]
  • Flutter Terms
  • Flutter Packages
  • Dart

Copyright © 2021 Flutter Website - by Flutter Team.

No Result
View All Result
  • Home
  • Categories
    • Flutter App
    • Flutter Examples
    • Flutter Github
    • Flutter News
    • Flutter PDF
    • Flutter Tips & Trick
    • Flutter Tutorial
    • Flutter UI
    • Flutter Video
    • Flutter VS
    • Flutter Wiki
    • Flutter With
  • Flutter
    • Flutter for Mobile
    • Flutter for Web
      • Widget Sample
    • Flutter for Desktop
    • Tools
      • Codemagic
      • Flutter Studio
      • Supernova
  • Showcase
  • Community
  • Advertisement
  • Hire Us
  • Login
  • Sign Up

Copyright © 2021 Flutter Website - by Flutter Team.

Welcome Back!

Sign In with Facebook
Sign In with Google
OR

Login to your account below

Forgotten Password? Sign Up

Create New Account!

Sign Up with Facebook
Sign Up with Google
OR

Fill the forms below to register

All fields are required. Log In

Retrieve your password

Please enter your username or email address to reset your password.

Log In
This website uses cookies. By continuing to use this website you are giving consent to cookies being used. Visit our Privacy and Cookie Policy.
Go to mobile version