<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/"
    xmlns:atom="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/" version="2.0">
    <channel>
        
        <title>
            <![CDATA[ push notification - freeCodeCamp.org ]]>
        </title>
        <description>
            <![CDATA[ Browse thousands of programming tutorials written by experts. Learn Web Development, Data Science, DevOps, Security, and get developer career advice. ]]>
        </description>
        <link>https://www.freecodecamp.org/news/</link>
        <image>
            <url>https://cdn.freecodecamp.org/universal/favicons/favicon.png</url>
            <title>
                <![CDATA[ push notification - freeCodeCamp.org ]]>
            </title>
            <link>https://www.freecodecamp.org/news/</link>
        </image>
        <generator>Eleventy</generator>
        <lastBuildDate>Sun, 26 Jul 2026 04:14:13 +0000</lastBuildDate>
        <atom:link href="https://www.freecodecamp.org/news/tag/push-notification/rss.xml" rel="self" type="application/rss+xml" />
        <ttl>60</ttl>
        
            <item>
                <title>
                    <![CDATA[ How to Add Push Notifications to a Flutter App using Firebase Cloud Messaging ]]>
                </title>
                <description>
                    <![CDATA[ By Krissanawat Flutter has quickly become one the most popular frameworks for cross-platform mobile application development. It helps developers build native UIs with support for different device sizes, pixel densities, and orientations creating a be... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-to-add-push-notifications-to-flutter-app/</link>
                <guid isPermaLink="false">66d46021ffe6b1f641b5fa2a</guid>
                
                    <category>
                        <![CDATA[ Firebase ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Flutter ]]>
                    </category>
                
                    <category>
                        <![CDATA[ messaging ]]>
                    </category>
                
                    <category>
                        <![CDATA[ push notification ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Wed, 09 Dec 2020 19:57:23 +0000</pubDate>
                <media:content url="https://cdn-media-2.freecodecamp.org/w1280/5fd0362ce6787e098393c56a.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Krissanawat</p>
<p>Flutter has quickly become one the most popular frameworks for cross-platform mobile application development. It helps developers build native UIs with support for different device sizes, pixel densities, and orientations creating a beautiful pixel-perfect UI/UX. </p>
<p>In this tutorial, we are going to learn how to add push notifications to a Flutter app using Firebase Cloud Messaging. This tutorial will only deal with configuration for the <strong>Android platform</strong>.</p>
<h3 id="heading-first-what-are-push-notifications">First, what are push notifications?</h3>
<p>Push Notifications are a sort of pop-up messaging medium that alerts app users to what's going on in the app. They are also an important way to amplify user engagement in your app. </p>
<p>For example, say a user forgets about the app once they have installed it. Then you can use push notifications as a mechanism to regain and retain their interest. Push notifications also help drive traffic to your app. </p>
<p>Firebase Cloud Messaging is a service offered by Firebase which lets you send these notifications to your users. You can set up various configurations to send different notifications to different audiences based on time and routine. </p>
<p>Because of all these benefits, we are going to use it to send notifications to our Flutter app.</p>
<h2 id="heading-step-1-create-a-flutter-project">Step 1: Create a Flutter Project</h2>
<p>First, we are going to create a flutter project. For that, we must have the Flutter SDK installed in our system. You can find simple steps for flutter installation in the official <a target="_blank" href="https://flutter.dev/docs/get-started/install">documentation</a>. </p>
<p>After you've successfully installed Flutter, you can simply run the following command in your desired directory to set up a complete Flutter project:</p>
<pre><code class="lang-jsx">flutter create pushNotification
</code></pre>
<p>After you've set up the project, navigate inside the project directory. Execute the following command in the terminal to run the project in either an available emulator or an actual device:</p>
<pre><code class="lang-bash">flutter run
</code></pre>
<p>After a successful build, you will get the following result in the emulator screen:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/12/image-69.png" alt="Image" width="600" height="400" loading="lazy"></p>
<h2 id="heading-step-2-integrate-firebase-configuration-with-flutter">Step 2: Integrate Firebase Configuration with Flutter</h2>
<p>In this step, we are going to integrate Firebase services with our Flutter project. But first, we need to create a Firebase project. The setup guidelines are also provided in the official <a target="_blank" href="https://firebase.google.com/docs/flutter/setup?platform=android">firebase documentation</a> for Flutter.</p>
<p>To create a Firebase project, we need to log in to <a target="_blank" href="https://firebase.google.com/">Firebase</a> and navigate to the console. There we can simply click on 'Add a project' to get our project started.</p>
<p>Then a window will appear asking to input the project's name. Here, I've kept the project name as <code>FlutterPushNotification</code> as shown in the screenshot below:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/12/image-70.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>We can continue to the next step when the project has been created. After the project has been set up, we will get a project console as shown in the screenshot below:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/12/image-71.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>Here, we are going to set up Firebase for the Android platform. So we need to click on the Android icon displayed in the above screenshot. This will lead us to the interface to register Firebase with our Flutter app project.</p>
<h2 id="heading-step-3-register-firebase-to-your-android-app">Step 3: Register Firebase to Your Android App</h2>
<p>As the registration process is platform-specific, we are going to register our app for the Android platform. After clicking on the Android icon, we will be directed to an interface asking for the <strong>Android package name</strong>. </p>
<p>In order to add the package name of our Flutter project, we need to locate it first. The package name will be available in the <strong>./android/app/build.gradle</strong> file of your Flutter project. You will see something like this:</p>
<pre><code class="lang-jsx">com.example.pushNotification
</code></pre>
<p>We just need to copy it and paste it to the Android package name input field as shown in the screenshot below:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/12/image-72.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>After that, we can simply click on the 'Register app' button. This will lead us to the interface where we can get the <strong>google-services.json</strong> file which will link our Flutter app to Firebase Google services. </p>
<p>We need to download the file and move it to the <strong>./android/app</strong> directory of our Flutter project. The instructions are also shown in the screenshot below:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/12/image-73.png" alt="Image" width="600" height="400" loading="lazy"></p>
<h2 id="heading-step-4-add-firebase-configurations-to-native-files-in-your-flutter-project">Step 4: Add Firebase Configurations to Native Files in your Flutter Project</h2>
<p>Now in order to enable Firebase services in our Android app, we need to add the <a target="_blank" href="https://developers.google.com/android/guides/google-services-plugin">google-services plugin</a> to our Gradle files.</p>
<p>First in our <strong>root-level (project-level)</strong> Gradle file (<strong>android/build.gradle</strong>), we need to add rules to include the Google Services Gradle plugin. We need to check if the following configurations are available or not:</p>
<pre><code class="lang-jsx">buildscript {
  repositories {
    <span class="hljs-comment">// Check that you have the following line (if not, add it):</span>
    google()  <span class="hljs-comment">// Google's Maven repository</span>
  }
  dependencies {
    ...
    <span class="hljs-comment">// Add this line</span>
    classpath <span class="hljs-string">'com.google.gms:google-services:4.3.4'</span>
  }
}

allprojects {
  ...
  repositories {
    <span class="hljs-comment">// Check that you have the following line (if not, add it):</span>
    google()  <span class="hljs-comment">// Google's Maven repository</span>
    ...
  }
}
</code></pre>
<p>If not, we need to add the configurations as shown in the code snippet above.</p>
<p>Now in our module (app-level) Gradle file (<strong>android/app/build.gradle</strong>), we need to apply the <strong>Google Services Gradle</strong> plugin. </p>
<p>For that, we need to add the piece of code highlighted in the following code snippet to the <strong>./android/app/build.gradle</strong> file of our project:</p>
<pre><code class="lang-jsx"><span class="hljs-comment">// Add the following line:</span>
**apply plugin: <span class="hljs-string">'com.google.gms.google-services'</span>**  <span class="hljs-comment">// Google Services plugin</span>

android {
  <span class="hljs-comment">// ...</span>
}
</code></pre>
<p>Now, we need to run the following command so that some automatic configurations can be made:</p>
<pre><code class="lang-jsx">flutter packages get
</code></pre>
<p>With that we have successfully integrated Firebase configurations with our Flutter project.</p>
<h2 id="heading-step-5-integrate-firebase-messaging-with-flutter">Step 5: Integrate Firebase Messaging with Flutter</h2>
<p>First, we need to add the firebase-messaging dependency to the <strong>./android/app/build.gardle</strong> file. In the file, we need to add the following dependencies:</p>
<pre><code class="lang-dart">dependencies {
    implementation <span class="hljs-string">"org.jetbrains.kotlin:kotlin-stdlib-jdk7:<span class="hljs-subst">$kotlin_version</span>"</span>
    implementation <span class="hljs-string">'com.google.firebase:firebase-messaging:20.1.0'</span>
}
</code></pre>
<p>Next, we need to add an <code>action</code> and a <code>category</code> as an <code>intent-filter</code> within the <code>activity</code> tag in the <strong>./android/app/src/main/AndroidManifest.xm</strong>l file:</p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">intent-filter</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">action</span> <span class="hljs-attr">android:name</span>=<span class="hljs-string">"FLUTTER_NOTIFICATION_CLICK"</span> /&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">category</span> <span class="hljs-attr">android:name</span>=<span class="hljs-string">"android.intent.category.DEFAULT"</span> /&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">intent-filter</span>&gt;</span>
</code></pre>
<p>Now, we need to create a Java file called <strong>Application.java</strong> in the path <strong>/android/app/src/main/java/</strong>.</p>
<p>Then, we need to add the code from the following code snippet inside it:</p>
<pre><code class="lang-java"><span class="hljs-keyword">package</span> io.flutter.plugins.pushNotification;

<span class="hljs-keyword">import</span> io.flutter.app.FlutterApplication;
<span class="hljs-keyword">import</span> io.flutter.plugin.common.PluginRegistry;
<span class="hljs-keyword">import</span> io.flutter.plugin.common.PluginRegistry.PluginRegistrantCallback;
<span class="hljs-keyword">import</span> io.flutter.plugins.GeneratedPluginRegistrant;
<span class="hljs-keyword">import</span> io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin;
<span class="hljs-keyword">import</span> io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService;

<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Application</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">FlutterApplication</span> <span class="hljs-keyword">implements</span> <span class="hljs-title">PluginRegistrantCallback</span> </span>{
    <span class="hljs-meta">@Override</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">onCreate</span><span class="hljs-params">()</span> </span>{
        <span class="hljs-keyword">super</span>.onCreate();
        FlutterFirebaseMessagingService.setPluginRegistrant(<span class="hljs-keyword">this</span>);
    }

    <span class="hljs-meta">@Override</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">registerWith</span><span class="hljs-params">(PluginRegistry registry)</span> </span>{
        FirebaseMessagingPlugin.registerWith(registry.registrarFor(<span class="hljs-string">"io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin"</span>));
    }
}
</code></pre>
<p>Now, we need to assign this <code>Application</code> activity to the <code>application</code> tag of the <strong>AndroidManifest.xml</strong> file as shown in the code snippet below:</p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">application</span>
        <span class="hljs-attr">android:name</span>=<span class="hljs-string">".Application"</span></span>
</code></pre>
<p>This completes our setup of the Firebase messaging plugin in the native Android code. Now, we'll move on to the Flutter project.</p>
<h2 id="heading-step-6-install-the-firebase-messaging-package">Step 6: Install the Firebase Messaging Package</h2>
<p>Here, we are going to use the <code>[firebase_messaging</code>] package, which <a target="_blank" href="https://pub.dev/packages/firebase_messaging/">you can find here</a>. For that, we need to add the plugin to the dependency option of the pubspec.yaml file. </p>
<p>We need to add the following line of code to the dependencies option:</p>
<pre><code class="lang-yaml"><span class="hljs-attr">firebase_messaging:</span> <span class="hljs-string">^7.0.3</span>
</code></pre>
<h2 id="heading-step-7-implement-a-simple-ui-screen">Step 7: Implement a Simple UI Screen</h2>
<p>Now, inside the <code>MyHomePage</code> stateful widget class of the <strong>main.dart</strong> file, we need to initialize the <code>FirebaseMessaging</code> instance and some constants as shown in the code snippet below:</p>
<pre><code class="lang-dart"><span class="hljs-built_in">String</span> messageTitle = <span class="hljs-string">"Empty"</span>;
<span class="hljs-built_in">String</span> notificationAlert = <span class="hljs-string">"alert"</span>;

FirebaseMessaging _firebaseMessaging = FirebaseMessaging();
</code></pre>
<p>The <code>messageTitle</code> variable will receive the notification message title and <code>notificationAlert</code> will be assigned the action that's been completed once the notification comes up.</p>
<p>Now, we need to apply these variables to the build function inside the <code>Scaffold</code> widget body as shown in the code snippet below:</p>
<pre><code class="lang-dart">Widget build(BuildContext context) {
    <span class="hljs-keyword">return</span> Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: &lt;Widget&gt;[
            Text(
              notificationAlert,
            ),
            Text(
              messageTitle,
              style: Theme.of(context).textTheme.headline4,
            ),
          ],
        ),
      ),
    );
  }
</code></pre>
<p>Next, we need to run the Flutter application by executing the following command in the project terminal:</p>
<pre><code class="lang-bash">flutter run
</code></pre>
<p>We will get the result you see in the image below:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/12/image-74.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>For now, the notification title is empty, and the alert is also as defined. We need to assign a proper value to them once we receive the notification message.</p>
<p>So we need to configure the code to receive the notification and use the notification message to display it on the screen.</p>
<p>For that, we need to add the code from the following code snippet in the <code>initiState</code> function:</p>
<pre><code class="lang-dart"><span class="hljs-meta">@override</span>
  <span class="hljs-keyword">void</span> initState() {
    <span class="hljs-comment">// <span class="hljs-doctag">TODO:</span> implement initState</span>
    <span class="hljs-keyword">super</span>.initState();

    _firebaseMessaging.configure(
      onMessage: (message) <span class="hljs-keyword">async</span>{
        setState(() {
          messageTitle = message[<span class="hljs-string">"notification"</span>][<span class="hljs-string">"title"</span>];
          notificationAlert = <span class="hljs-string">"New Notification Alert"</span>;
        });

      },
      onResume: (message) <span class="hljs-keyword">async</span>{
        setState(() {
          messageTitle = message[<span class="hljs-string">"data"</span>][<span class="hljs-string">"title"</span>];
          notificationAlert = <span class="hljs-string">"Application opened from Notification"</span>;
        });

      },
    );
  }
</code></pre>
<p>Here, we have used the <code>configure</code> method provided by <code>_firebaseMessaging</code> instance which in turn provides the <code>onMessage</code> and <code>onResume</code> callbacks. These callbacks provide the notification <code>message</code> as a parameter. The <code>message</code> response will hold the notification object as a map object.</p>
<p>The <code>onMessage</code> function triggers when the notification is received while we are running the app. The <code>onResume</code> function triggers when we receive the notification alert in the device notification bar and opens the app through the push notification itself. In this case, the app can be running in the background or not running at all.</p>
<p>Now we are all equipped with the Flutter app. We just need to configure a message in Firebase Cloud Messaging and send it to the device.</p>
<h2 id="heading-step-8-create-a-message-from-the-firebase-cloud-messaging-console">Step 8: Create a Message from the Firebase Cloud Messaging Console</h2>
<p>First, we need to go back to the Cloud Messaging console in the Firebase site as shown in the image below:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/12/image-75.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>Here, we can see the 'Send your first message' option in the window, as we have not configured any messages before. We need to click on it which will lead us to the following window:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/12/image-76.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>Here, we can enter the title, text, image, and name of the notification. The title we set here will be provided as the title in the <code>message</code> object on the callbacks we set before in the Flutter project.</p>
<p>After setting the required fields, we can click on 'Next' which will lead us to the following window:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/12/image-77.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>Here, we need to provide our target app and click on 'Next'.</p>
<p>For Scheduling we can keep the default option:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/12/image-78.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>Next, the Conversion window will appear which we can keep as default as well, and then click on the 'Next' button.</p>
<p>Lastly, a window where we need to enter the custom data will appear in which we can set the <code>title</code> and <code>click_action</code>. This click action event is triggered whenever we click on the notification that appears in the notification bar of the device. </p>
<p>After clicking on the notification message from the notification bar, the app will open and the <code>onResume</code> callback will trigger, setting <code>title</code> as assigned in the custom data in the screenshot below:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/12/image-79.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>Now, we are ready to send the first notification message to the device. First, let's try it with the device running in the emulator.</p>
<p>As we click on the 'Review' button and send the message, we will get the following result in the Cloud Messaging console as well as the emulator:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/12/pushGIF1.gif" alt="Image" width="600" height="400" loading="lazy"></p>
<p>Here, we can see that the title and the notification alert on the emulator screen are updated as soon as we send a message from the console. We can be sure that the <code>onMessage</code> callback was triggered in the app after receiving the notification message.</p>
<p>Now let's try with the app running in the background. As we send the message from the console, we will get the result as shown in the demo below:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/12/pushGIF2.gif" alt="Image" width="600" height="400" loading="lazy"></p>
<p>Here, as soon as we send the message, we receive a push notification in the notification bar of the device. Then, as we drag down the notification bar, we can see the notification message title and text. And, by clicking on the notification message, we can launch the application and display the custom data on the screen. This ensures that our <code>onResume</code> callback was triggered.</p>
<p>And we're done! We have successfully added a push notification feature in our Flutter application using Firebase Cloud Messaging.</p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>Push notifications are essential in any app. They can be used to alert users to what's going on in the app, and can help drive users' interest back to the app. </p>
<p>Additionally, Firebase Cloud Messaging makes sending notification alerts much simpler and easier. </p>
<p>In this tutorial, we started by configuring the Firebase app and then moved on to the setup and implementation of the Firebase messaging configuration in the Flutter app. Lastly, we were able to send notification alerts to the app using Firebase Cloud Messaging. </p>
<p>The tutorial was meant to be simple and easy to understand. Hope that it helps you add push notification to your Flutter apps. Want to see some examples of how you can implement all this? Check out these powerful <a target="_blank" href="http://instaflutter.com">Flutter templates</a>.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to get push notifications working with Ionic 4 and Firebase ]]>
                </title>
                <description>
                    <![CDATA[ By Filip Jerga A full step-by-step tutorial that will get you on the right track for iOS and Android Setting up push notifications can be truly frustrating and time consuming. So I went through all of the setups and prepared this tutorial for you. P... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-to-get-push-notifications-working-with-ionic-4-and-firebase-ad87cc92394e/</link>
                <guid isPermaLink="false">66c3523ad58e4fdd567d518f</guid>
                
                    <category>
                        <![CDATA[ Apps ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Firebase ]]>
                    </category>
                
                    <category>
                        <![CDATA[ General Programming ]]>
                    </category>
                
                    <category>
                        <![CDATA[ push notification ]]>
                    </category>
                
                    <category>
                        <![CDATA[ tech  ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Thu, 25 Oct 2018 14:27:04 +0000</pubDate>
                <media:content url="https://cdn-media-1.freecodecamp.org/images/1*EciBTQhuzIrkzA12dfsQJQ.jpeg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Filip Jerga</p>
<h4 id="heading-a-full-step-by-step-tutorial-that-will-get-you-on-the-right-track-for-ios-and-android">A full step-by-step tutorial that will get you on the right track for iOS and Android</h4>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*EciBTQhuzIrkzA12dfsQJQ.jpeg" alt="Image" width="800" height="531" loading="lazy"></p>
<p>Setting up push notifications can be truly frustrating and time consuming. So I went through all of the setups and prepared this tutorial for you.</p>
<h3 id="heading-prerequisite">Prerequisite</h3>
<p>Ionic 4 should already be installed.</p>
<h3 id="heading-section-navigation">Section navigation</h3>
<ol>
<li><a target="_blank" href="https://www.freecodecamp.org/news/how-to-get-push-notifications-working-with-ionic-4-and-firebase-ad87cc92394e/#1-package-installation">Package installation</a></li>
<li><a target="_blank" href="https://www.freecodecamp.org/news/how-to-get-push-notifications-working-with-ionic-4-and-firebase-ad87cc92394e/#2-firebase-setup-for-ios-and-android">Firebase setup for Android and iOS</a></li>
<li><a target="_blank" href="https://www.freecodecamp.org/news/how-to-get-push-notifications-working-with-ionic-4-and-firebase-ad87cc92394e/#3-push-notification-code-implementation">Push notification code implementation</a></li>
<li><a target="_blank" href="https://www.freecodecamp.org/news/how-to-get-push-notifications-working-with-ionic-4-and-firebase-ad87cc92394e/#4-test-push-notifications-on-android">Test push notifications on Android</a></li>
<li><a target="_blank" href="https://www.freecodecamp.org/news/how-to-get-push-notifications-working-with-ionic-4-and-firebase-ad87cc92394e/#5-ios-push-notification-pre-setup">iOS push notification pre-setup</a></li>
<li><a target="_blank" href="https://www.freecodecamp.org/news/how-to-get-push-notifications-working-with-ionic-4-and-firebase-ad87cc92394e/#6-test-push-notification-on-ios">Test push notifications on iOS</a></li>
</ol>
<h3 id="heading-1-package-installation">1. Package installation</h3>
<p>Open your Ionic project in the coding editor of your choice, and open your terminal as well. Navigate to your project’s folder.</p>
<p>First, we will install all of the required packages.</p>
<p><strong>What we need to install:</strong></p>
<ul>
<li><strong>Cordova plugin for firebase:</strong> <code>ionic cordova plugin add cordova-plugin-firebase</code></li>
<li><strong>Firebase native package:</strong> since Ionic 4 is in beta, check your Ionic-native packages in <code>package.json</code> and install the same version as other Ionic-native packages. Finally, let’s type: <code>npm install --save @ionic-native/firebase@5.0.0-beta.14</code></li>
</ul>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*4R0G8E3rY6N8xrwRYpWO8A.png" alt="Image" width="732" height="98" loading="lazy">
<em>I have version of beta.14</em></p>
<ul>
<li>One last package, <strong>AngularFire 2</strong>. This is a library for Angular and Firebase: <code>npm install --save angularfire2 firebase</code></li>
</ul>
<p>Packages install, done! Let’s move to the second section.</p>
<h3 id="heading-2-firebase-setup-for-ios-and-android">2. Firebase setup for iOS and Android</h3>
<p>Before we will start all of the setup, I need to warn you that you cannot test your push notifications on iOS emulator. To test it out you need to have an Apple Developer account, which costs around $99USD per year. I suggest you to go through iOS setup anyway so it will give you a better understanding for future projects.</p>
<p><strong>Note:</strong> The steps starting here are very important, so please be patient. Read slowly and make sure you get everything right. Looking for issues after all of the setup can be very frustrating, trust me — I am speaking from my own experience.</p>
<h4 id="heading-ios">iOS</h4>
<p><a target="_blank" href="https://firebase.google.com">Navigate to the Firebase page</a> and login to a console. If you don’t have a project created yet, do it now. You should see this screen.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*YKEMKgcl7nukC-1QOOqmAw.png" alt="Image" width="800" height="509" loading="lazy"></p>
<p>Click on the iOS button and you’ll see this:</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*yzwF8xD5qUFfy5yBWmmkZw.png" alt="Image" width="800" height="443" loading="lazy"></p>
<p>Now we need to provide our iOS bundle ID and this has to be the same as in your Ionic project. Let’s say I want to have the bundle name <code>com.filipjerga.angularcourse</code>, then I need to do the following:</p>
<p>Open your Ionic projects and navigate to “config.xml” file. Let’s inspect the widget element. The <strong>Id</strong> attribute holds the unique identifier of your application<strong>.</strong> I said before if you specified your bundle name to <code>com.filipjerga.angularcourse</code> in Firebase, the <strong>id</strong> in your Ionic project has to be the same! You can also leave the <strong>id</strong> as you have it already in your Ionic project but then you need to change it in Firebase.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*nKaEn3rqKjQQSK5DbOTx1Q.png" alt="Image" width="800" height="35" loading="lazy">
<em>widget element id is what we need to specify in Firebase</em></p>
<p>After you get the value of <strong>id,</strong> don’t forget to provide it to your Firebase application as the bundle ID.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*80_WthW7_5CQbd5Dcg6BvA.png" alt="Image" width="800" height="596" loading="lazy">
<em>Bundle ID has to be a same as your widget id</em></p>
<p>That should be everything in the first step of registering the application. This step is crucial, so double check the value of <strong>id</strong> on the widget and bundle ID of your Firebase application<strong>.</strong></p>
<p>Leave the other fields blank and click “Register app”.</p>
<p>Now we need to download “GoogleService-Info.plist”.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*OdG0hBlzpiMMvYT7w6gPxg.png" alt="Image" width="800" height="135" loading="lazy"></p>
<p>When it’s downloaded, paste it into a base folder of your projects. You can see a folder structure in <a target="_blank" href="https://github.com/Jerga99/heartStoneLib">my project here</a>.</p>
<p>We can skip all of the further steps, as they are not required for the Ionic project setup. You should have your IOS application ready.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*HVdgpvS2Rv2a1dfuNDPgtw.png" alt="Image" width="800" height="170" loading="lazy">
<em>Skip this step</em></p>
<h4 id="heading-android">Android</h4>
<p>The following steps for Android are almost the same as for the iOS setup:</p>
<ul>
<li>Click ‘add app’ for Android, same as we did in iOS before.</li>
<li>The Android package name needs to be the same as our widget id, in my case: <code>com.filipjerga.angularcourse</code></li>
<li>Next, download <code>google-services.json</code><strong>.</strong> Same as before with the iOS file, we need to copy it to the base folder of our applications</li>
<li>Click “Next” until you are on the last step, which you can skip, and you should end up with both applications created.</li>
</ul>
<p>Yay! Congrats! But it’s still too early to cheer.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*QN0VI93SeNd5aJ1-yDHJSg.png" alt="Image" width="800" height="110" loading="lazy">
<em>Both iOS and Angular apps created.</em></p>
<h3 id="heading-3-push-notification-code-implementation">3. Push notification code implementation</h3>
<h4 id="heading-package-importing">Package importing</h4>
<p>The time has come to finally warm up our fingers by typing some code. We will start with importing the packages we installed before.</p>
<ol>
<li>Go to <code>app.module.ts</code></li>
<li>Your file should look like this:</li>
</ol>
<pre><code class="lang-ts"><span class="hljs-keyword">import</span> { NgModule } <span class="hljs-keyword">from</span> <span class="hljs-string">'@angular/core'</span>;
<span class="hljs-keyword">import</span> { BrowserModule } <span class="hljs-keyword">from</span> <span class="hljs-string">'@angular/platform-browser'</span>;
<span class="hljs-keyword">import</span> { RouterModule, RouteReuseStrategy } <span class="hljs-keyword">from</span> <span class="hljs-string">'@angular/router'</span>;

<span class="hljs-keyword">import</span> { IonicModule, IonicRouteStrategy } <span class="hljs-keyword">from</span> <span class="hljs-string">'@ionic/angular'</span>;
<span class="hljs-keyword">import</span> { SplashScreen } <span class="hljs-keyword">from</span> <span class="hljs-string">'@ionic-native/splash-screen/ngx'</span>;
<span class="hljs-keyword">import</span> { StatusBar } <span class="hljs-keyword">from</span> <span class="hljs-string">'@ionic-native/status-bar/ngx'</span>;

<span class="hljs-keyword">import</span> { AppRoutingModule } <span class="hljs-keyword">from</span> <span class="hljs-string">'./app-routing.module'</span>;
<span class="hljs-keyword">import</span> { AppComponent } <span class="hljs-keyword">from</span> <span class="hljs-string">'./app.component'</span>;

<span class="hljs-keyword">import</span> { AngularFireModule } <span class="hljs-keyword">from</span> <span class="hljs-string">'angularfire2'</span>;
<span class="hljs-keyword">import</span> { AngularFirestoreModule } <span class="hljs-keyword">from</span> <span class="hljs-string">'angularfire2/firestore'</span>;
<span class="hljs-keyword">import</span> { Firebase } <span class="hljs-keyword">from</span> <span class="hljs-string">'@ionic-native/firebase/ngx'</span>;

<span class="hljs-keyword">const</span> config = {
    apiKey: <span class="hljs-string">"AIzaSyD-K6SlFECXKmd8iHwEvggVtavKgyPF2k8"</span>,
    authDomain: <span class="hljs-string">"angular2-course-9270e.firebaseapp.com"</span>,
    databaseURL: <span class="hljs-string">"https://angular2-course-9270e.firebaseio.com"</span>,
    projectId: <span class="hljs-string">"angular2-course-9270e"</span>,
    storageBucket: <span class="hljs-string">"angular2-course-9270e.appspot.com"</span>,
    messagingSenderId: <span class="hljs-string">"443316848633"</span>
  };

<span class="hljs-meta">@NgModule</span>({
  declarations: [AppComponent],
  entryComponents: [],
  imports: [
    BrowserModule,
    IonicModule.forRoot(),
    AppRoutingModule,
    IonicStorageModule.forRoot(),
    AngularFireModule.initializeApp(config),
    AngularFirestoreModule],
  providers: [
    StatusBar,
    SplashScreen,
    Firebase,
    { provide: RouteReuseStrategy, useClass: IonicRouteStrategy }
  ],
  bootstrap: [AppComponent]
})
<span class="hljs-keyword">export</span> <span class="hljs-keyword">class</span> AppModule {}
</code></pre>
<p>You can see <code>Firebase</code> in the providers array, and <code>AngularFirestoreModule</code> and <code>AngularFireModule</code> in imports.</p>
<p>But where did the <code>config</code> object came from ? You can see lot of information there as “apiKey, authDomain” and so on.</p>
<p>To answer this we need go back to our Firebase console and create a <strong>web app</strong>.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*js9Izqbu8Bceb2kIZSDzRg.png" alt="Image" width="752" height="224" loading="lazy">
<em>Select web platform</em></p>
<p>You need to click on a web platform icon on the right from the Android icon (see the image above). When the web app is selected you will be presented with your own <strong>config</strong> object.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*5a3ry984v5Mer9Ob63axZQ.png" alt="Image" width="800" height="324" loading="lazy">
<em>My config object for Firebase after selecting web app.</em></p>
<p>Now it’s time to copy whole <strong>config</strong> object to <code>app.module.ts</code> in our Ionic projects. Please <strong>make sure</strong> you change it for your config object! Mine will not work for you.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*Gkp_0kiAs4f_t3UL_hUNVw.png" alt="Image" width="800" height="302" loading="lazy">
<em>Provide config to app.module.ts</em></p>
<p>Now we can start working on the implementation of the push notification service.</p>
<h4 id="heading-push-notification-service">Push notification service</h4>
<p>Let’s create a new service. Call it what you like. I will call mine <code>fcm.service.ts</code>. FCM stands for Firebase Cloud Messaging.</p>
<p>First, let’s take a look at the service implementation. I will explain it line by line.</p>
<pre><code class="lang-ts"><span class="hljs-keyword">import</span> { Injectable } <span class="hljs-keyword">from</span> <span class="hljs-string">'@angular/core'</span>;
<span class="hljs-keyword">import</span> { Firebase } <span class="hljs-keyword">from</span> <span class="hljs-string">'@ionic-native/firebase/ngx'</span>;
<span class="hljs-keyword">import</span> { Platform } <span class="hljs-keyword">from</span> <span class="hljs-string">'@ionic/angular'</span>;
<span class="hljs-keyword">import</span> { AngularFirestore } <span class="hljs-keyword">from</span> <span class="hljs-string">'angularfire2/firestore'</span>;

<span class="hljs-meta">@Injectable</span>()
<span class="hljs-keyword">export</span> <span class="hljs-keyword">class</span> FcmService {

  <span class="hljs-keyword">constructor</span>(<span class="hljs-params"><span class="hljs-keyword">private</span> firebase: Firebase,
              <span class="hljs-keyword">private</span> afs: AngularFirestore,
              <span class="hljs-keyword">private</span> platform: Platform</span>) {}

  <span class="hljs-keyword">async</span> getToken() {
    <span class="hljs-keyword">let</span> token;

    <span class="hljs-keyword">if</span> (<span class="hljs-built_in">this</span>.platform.is(<span class="hljs-string">'android'</span>)) {
      token = <span class="hljs-keyword">await</span> <span class="hljs-built_in">this</span>.firebase.getToken();
    }

    <span class="hljs-keyword">if</span> (<span class="hljs-built_in">this</span>.platform.is(<span class="hljs-string">'ios'</span>)) {
      token = <span class="hljs-keyword">await</span> <span class="hljs-built_in">this</span>.firebase.getToken();
      <span class="hljs-keyword">await</span> <span class="hljs-built_in">this</span>.firebase.grantPermission();
    }

    <span class="hljs-built_in">this</span>.saveToken(token);
  }

  <span class="hljs-keyword">private</span> saveToken(token) {
    <span class="hljs-keyword">if</span> (!token) <span class="hljs-keyword">return</span>;

    <span class="hljs-keyword">const</span> devicesRef = <span class="hljs-built_in">this</span>.afs.collection(<span class="hljs-string">'devices'</span>);

    <span class="hljs-keyword">const</span> data = {
      token,
      userId: <span class="hljs-string">'testUserId'</span>
    };

    <span class="hljs-keyword">return</span> devicesRef.doc(token).set(data);
  }

  onNotifications() {
    <span class="hljs-keyword">return</span> <span class="hljs-built_in">this</span>.firebase.onNotificationOpen();
  }
}
</code></pre>
<p>If we want to send a push notification to a device, we need to get an unique identifier of the device. In this case it’s called a <code>token</code>.</p>
<p>We need to check for a platform specific device, because of an additional step in the iOS setup. iOS requires explicit permissions to receive push notifications.</p>
<p>Now we need to store this token somewhere, but where? We will store tokens in the <strong>Firebase database</strong>. You can see, I am creating <strong>device</strong> collections and I am filling them with <code>data</code> that contains the <code>token</code> and just a testing <code>UserId</code>. Perfect! Now, we have stored our token and we can subscribe to notifications.</p>
<p>Subscribing to notifications is actually very simple. We just need to call <code>this.firebase.onNotificationOpen()</code></p>
<p>Amazing. Service checked!</p>
<p>All of this is nice but kinda useless, since we are not using our service yet. Let’s fix it!</p>
<p>Move to your <code>app.component.ts</code> and write the following:</p>
<pre><code class="lang-ts"><span class="hljs-keyword">import</span> { Component } <span class="hljs-keyword">from</span> <span class="hljs-string">'@angular/core'</span>;

<span class="hljs-keyword">import</span> { Platform } <span class="hljs-keyword">from</span> <span class="hljs-string">'@ionic/angular'</span>;
<span class="hljs-keyword">import</span> { SplashScreen } <span class="hljs-keyword">from</span> <span class="hljs-string">'@ionic-native/splash-screen/ngx'</span>;
<span class="hljs-keyword">import</span> { StatusBar } <span class="hljs-keyword">from</span> <span class="hljs-string">'@ionic-native/status-bar/ngx'</span>;

<span class="hljs-keyword">import</span> { FcmService } <span class="hljs-keyword">from</span> <span class="hljs-string">'./shared/service/fcm.service'</span>;
<span class="hljs-keyword">import</span> { ToastService } <span class="hljs-keyword">from</span> <span class="hljs-string">'./shared/service/toast.service'</span>;
<span class="hljs-keyword">import</span> { ToastController } <span class="hljs-keyword">from</span> <span class="hljs-string">'@ionic/angular'</span>;

<span class="hljs-meta">@Component</span>({
  selector: <span class="hljs-string">'app-root'</span>,
  templateUrl: <span class="hljs-string">'app.component.html'</span>
})
<span class="hljs-keyword">export</span> <span class="hljs-keyword">class</span> AppComponent {

  <span class="hljs-keyword">constructor</span>(<span class="hljs-params">
    <span class="hljs-keyword">private</span> platform: Platform,
    <span class="hljs-keyword">private</span> splashScreen: SplashScreen,
    <span class="hljs-keyword">private</span> statusBar: StatusBar,
    <span class="hljs-keyword">private</span> fcm: FcmService,
    <span class="hljs-keyword">private</span> toastr: ToastService,
    <span class="hljs-keyword">public</span> toastController: ToastController

  </span>) {
    <span class="hljs-built_in">this</span>.initializeApp();
  }

  <span class="hljs-keyword">private</span> <span class="hljs-keyword">async</span> presentToast(message) {
    <span class="hljs-keyword">const</span> toast = <span class="hljs-keyword">await</span> <span class="hljs-built_in">this</span>.toastController.create({
      message,
      duration: <span class="hljs-number">3000</span>
    });
    toast.present();
  }

  <span class="hljs-keyword">private</span> notificationSetup() {
    <span class="hljs-built_in">this</span>.fcm.getToken();
    <span class="hljs-built_in">this</span>.fcm.onNotifications().subscribe(
      <span class="hljs-function">(<span class="hljs-params">msg</span>) =&gt;</span> {
        <span class="hljs-keyword">if</span> (<span class="hljs-built_in">this</span>.platform.is(<span class="hljs-string">'ios'</span>)) {
          <span class="hljs-built_in">this</span>.presentToast(msg.aps.alert);
        } <span class="hljs-keyword">else</span> {
          <span class="hljs-built_in">this</span>.presentToast(msg.body);
        }
      });
  }

  initializeApp() {
    <span class="hljs-built_in">this</span>.platform.ready().then(<span class="hljs-function">() =&gt;</span> {
      <span class="hljs-built_in">this</span>.statusBar.styleDefault();
      <span class="hljs-built_in">this</span>.splashScreen.hide();
      <span class="hljs-built_in">this</span>.notificationSetup();
    });
  }
}
</code></pre>
<p>Especially important here is the function <code>notificationSetup</code>.</p>
<p>We are getting an unique token of the device first.</p>
<p>We are also subscribing to incoming notifications from Firebase.</p>
<p>When the message is received, we need to check, again, for specific platforms. On iOS your message text is under <code>aps.alert</code> . On Android it’s under <code>body</code>.</p>
<p>Then we will just simply display the received message as a <code>Toast</code>.</p>
<p>Now the code setup is done. We are getting very close! It’s time to test it out.</p>
<h3 id="heading-4-test-push-notifications-on-android">4. Test push notifications on Android</h3>
<p>All of the required setup for Android should be done right now. You can start emulating your app by:</p>
<p><code>ionic cordova emulate android</code></p>
<p>or</p>
<p><code>ionic cordova build android</code> and open your build manually in Android Studio.</p>
<p>Let’s launch our applications and go to a Home menu, so we will see a push notification there. Make sure your application was launched properly in emulator and you have no errors.</p>
<p>Go back to your browsers to your Firebase Applications. Now it’s time to inspect our Firebase Database. You can find the database option in the left panel under the <strong>Develop</strong> category.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*ev05fxLy5yySp_Xa-uA4JQ.png" alt="Image" width="434" height="268" loading="lazy">
<em>Firebase Database</em></p>
<p>After your application was launched in emulators, the code from <strong>app.component.ts</strong> we wrote a few moments ago ran. No wonder our database is populated. In the “saveToken” function we specified the “devices” collection and we saved the token with the user id as a document into this devices collection. That is what we see in our database.</p>
<p>In my case, I have multiple tokens in my database but you should have only one since we’ve run our app the first time. You will create a new document per unique device/emulator you are running your app on.</p>
<p>Now it’s time to copy this token in order to send push notification to a specific device.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*tGtpXyvp46jGuGr9SzsBTg.png" alt="Image" width="800" height="145" loading="lazy">
<em>Firebase database collection, You will see only one document</em></p>
<p><strong>Navigate to the left panel to a grow tab</strong> and click on cloud messaging.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*_oO9cu4Gw3IAXbvGuWeWOQ.png" alt="Image" width="454" height="276" loading="lazy">
<em>Click on Cloud Messaging</em></p>
<p>Now we need to fill in the necessary data. Enter the text of your message and provide the token of the device from the database we just copied.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*vdXEcVntcKkfqr8ll49r6Q.png" alt="Image" width="800" height="742" loading="lazy"></p>
<p>When you are sending a message, open your emulated device simultaneously and watch what happens.</p>
<p>Send a message, aaaaand Congrats! Now your Android setup is done and you are able to send push notifications! Isn’t that awesome?</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*HwQKVZAHeF6Tb1QZV46Zzw.png" alt="Image" width="582" height="1232" loading="lazy">
<em>Push notification on Android.</em></p>
<h3 id="heading-5-ios-push-notification-pre-setup">5. iOS push notification pre-setup</h3>
<p>Buckle up guys, iOs setup is coming. Let’s separate this setup into multiple steps, so we will not have a panic attack. Let’s dig in!</p>
<p><strong>First,</strong> build your application for iOS: <code>ionic cordova build ios</code></p>
<p>Open your Xcode, and find your built app in <code>platforms/ios/nameofyourapp.xcodeproj</code> . Open it.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*2J27mF3dE36yro4TDuDbZA.png" alt="Image" width="800" height="453" loading="lazy">
<em>Open your .xcodeproj</em></p>
<p>This should open a tree structure of your application on the left side. Double Click the root file of this structure. This will open an additional menu with more settings for your app.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*CwCbrVvqy_lYJhOHahe5qQ.png" alt="Image" width="800" height="87" loading="lazy">
<em>More settings</em></p>
<p>Sign in with your developer account.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*AD1U9EEfHRozZHoUn3d5Ng.png" alt="Image" width="800" height="229" loading="lazy">
<em>Sign in with a developer account</em></p>
<ol start="5">
<li>Open the top “Capabilities” tab and enable “Push Notifications”.</li>
</ol>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*4lOdzB6p9BWGiVkYuC1G1w.png" alt="Image" width="800" height="118" loading="lazy">
<em>Enable Push Notifications</em></p>
<ol start="6">
<li>Navigate to your <a target="_blank" href="https://developer.apple.com">Apple developer account page</a>. Under “Certificates” select “All” and click "<code>+"</code> to <strong>add</strong> a new certificate.</li>
</ol>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*M_sJ-0Y6UcfCSXvZexoh9g.png" alt="Image" width="800" height="105" loading="lazy">
<em>Click the plus sign.</em></p>
<p>Enable the Apple Push Notification service and proceed to the next step.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*sUsADfJUdEJcyi2xblFjwg.png" alt="Image" width="800" height="153" loading="lazy"></p>
<p>Now let’s choose your application.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*nXick1xCKeQt8Xrv5LSdvw.png" alt="Image" width="800" height="100" loading="lazy"></p>
<p>We need to <strong>request a certificate</strong>. On your Mac, go to “Keychain Access” -&gt; “Certificate Assistant” -&gt; “Request a Certificate From a Certificate Authority”.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*rhTf5N0TL1AmKoXcWbhfoQ.png" alt="Image" width="800" height="213" loading="lazy"></p>
<p>Complete all the necessary information — your email and common name — and save it to disk.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*ytVFGho1inBYnv2pYYLLbA.png" alt="Image" width="778" height="302" loading="lazy"></p>
<p>In the Apple Console proceed to the next step and <strong>upload</strong> your certificate request.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*Qlz9edFubew4V3ozdt2X7A.png" alt="Image" width="800" height="256" loading="lazy"></p>
<p>In the next step your certificate should be created and you can download it. <strong>You will need it later.</strong></p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*n5YZm8E6QYxNCDb9Ns7tyQ.png" alt="Image" width="800" height="220" loading="lazy"></p>
<p>Now we need to <strong>create a service key</strong> to enable Apple push notifications. Under “Keys” select “All” . Choose your key name. Enable “Apple Push Notifications service (APNs)”.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*8lXVFTpEjwrApP2FArRaew.png" alt="Image" width="800" height="322" loading="lazy"></p>
<p>Click “Continue” and confirm your key. <strong>Never share such data with others.</strong> You can now download your key.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*S_gRFhnecm29gSTaSWpfiA.png" alt="Image" width="800" height="217" loading="lazy"></p>
<p>Now we need to go back to Firebase.</p>
<p>In Firebase, open your iOS application and navigate to “Cloud Messaging”.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*10JoxYxq7LPUNv_magHS9A.png" alt="Image" width="800" height="142" loading="lazy"></p>
<p>We need to <strong>upload</strong> our APN Authentication Key we generated a while ago. Click “Upload”.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*jZtNNpy7gTjsv4tjZfsy9A.png" alt="Image" width="800" height="298" loading="lazy"></p>
<p>Provide all the information and upload the key.</p>
<p>First, upload your “.p8” file, downloaded from the Apple console earlier. Enter your Key ID. You can get the App ID prefix from the Apple console in “Identifiers”-&gt;“App IDs”-&gt;“Your App”-&gt;“Prefix”.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*TKeh5ZvgKRN6MXZvw7e0qw.png" alt="Image" width="800" height="678" loading="lazy"></p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*l7g5BPKU9GvG0c9RJFWTUA.png" alt="Image" width="800" height="262" loading="lazy">
<em>Upload p8 file and get keyID and ID prefix</em></p>
<p>That’s it. Tears of joy are running down my face.</p>
<p>We can test Push Notifications on iOS. Let’s not forget we need to use a real device.</p>
<h3 id="heading-6-test-push-notification-on-ios">6. Test push notification on iOS</h3>
<p>First, we need to build our applications so let’s run: <code>ionic cordova build ios</code></p>
<p>In Xcode you can run your application on a device connected by USB with your computer.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*f4NOHT2xCJPgd2SXCXl-EA.png" alt="Image" width="734" height="332" loading="lazy">
<em>Choose your device</em></p>
<p>Let’s wait until everything is launched. We can now repeat the steps to send push notifications from <a target="_blank" href="https://medium.com/p/ad87cc92394e#0d9c"><strong>Section 4</strong></a><strong>,</strong> because it is the same as on Android.</p>
<p>Remember that <strong>you need to use a new token</strong> now, that was generated for your iOS device. Go to Databases, get a new token, and send a push notification. Your result should look like this.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*ZOE5hMQpOWxUIfE9zjDyfg.png" alt="Image" width="800" height="647" loading="lazy"></p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*zBEkbPOB6EEurPt5j3qzrw.png" alt="Image" width="800" height="1413" loading="lazy"></p>
<p>I hope you have been successful with setting up your push notifications. It takes some time and patience to get everything right, but the outcome and benefits are amazing.</p>
<p>If you like my tutorial and you are interested in more, you can check out my course on Udemy: <a target="_blank" href="http://bit.ly/2Ne2PhK"><strong>Ionic 4 Crash Course with Heartstone API and Angular.</strong></a></p>
<p>For a full project see <a target="_blank" href="https://github.com/Jerga99/heartStoneLib">my Github Repo</a>.</p>
<p>Happy Coding!</p>
<p>Filip</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to add push notifications to a web app with Firebase ?+? ]]>
                </title>
                <description>
                    <![CDATA[ By Leonardo Cardoso As web applications evolve, it is increasingly common to come across functionality that you’d normally associate with a native app in a web app. Many sites send notifications to their users through the browser for various events t... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-to-add-push-notifications-to-a-web-app-with-firebase-528a702e13e1/</link>
                <guid isPermaLink="false">66c34ee35ced6d98e4bd3329</guid>
                
                    <category>
                        <![CDATA[ Firebase ]]>
                    </category>
                
                    <category>
                        <![CDATA[ JavaScript ]]>
                    </category>
                
                    <category>
                        <![CDATA[ General Programming ]]>
                    </category>
                
                    <category>
                        <![CDATA[ push notification ]]>
                    </category>
                
                    <category>
                        <![CDATA[ tech  ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Wed, 04 Jul 2018 16:03:45 +0000</pubDate>
                <media:content url="https://cdn-media-1.freecodecamp.org/images/0*dRRGbswavkQQyO_P.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Leonardo Cardoso</p>
<p>As web applications evolve, it is increasingly common to come across functionality that you’d normally associate with a native app in a web app. Many sites send notifications to their users through the browser for various events that occur within the web app.</p>
<p>Today, I’ll show you the steps required, in detail, to achieve such functionality in your web app using <strong>Firebase</strong>.</p>
<h3 id="heading-notifications-with-firebase">Notifications with Firebase</h3>
<p>Firebase is a platform that offers various services for mobile and web applications and helps developers build apps quickly with a lot of features.</p>
<p>To send the notifications, we will use the service called <a target="_blank" href="https://firebase.google.com/docs/cloud-messaging/">Cloud Messaging</a>, which allows us to send messages to any device using HTTP requests.</p>
<h3 id="heading-project-setup">Project Setup</h3>
<p>First of all, you need to have a <a target="_blank" href="https://console.firebase.google.com">Firebase</a> account and you’ll need to create a new project within it.</p>
<p>For this demo setup, I will use a simple project created with the <a target="_blank" href="https://github.com/facebook/create-react-app"><strong>create-react-app</strong></a>, but you can use the same code anywhere else that uses JavaScript.</p>
<p>In addition to that, we need to add the Firebase library to the project.</p>
<pre><code class="lang-bash">npm install firebase --save
</code></pre>
<h3 id="heading-so-lets-get-coding">So let’s get coding!</h3>
<p>Now that we’ve done our setup, we can begin coding the module that will be in charge of notifications.</p>
<p>Let’s create a file inside the project directory called <code>push-notification.js</code>.</p>
<p>Inside the file, let’s create a function that initializes Firebase and passes the keys of your project.</p>
<pre><code class="lang-js"><span class="hljs-keyword">import</span> firebase <span class="hljs-keyword">from</span> <span class="hljs-string">'firebase'</span>;

<span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> initializeFirebase = <span class="hljs-function">() =&gt;</span> {
  firebase.initializeApp({
    <span class="hljs-attr">messagingSenderId</span>: <span class="hljs-string">"your messagingSenderId"</span>
  });
}
</code></pre>
<p>Well, now that we have the function we need to call it.</p>
<p>Inside the entry point of your project, import the function and call it.</p>
<pre><code class="lang-js"><span class="hljs-keyword">import</span> React <span class="hljs-keyword">from</span> <span class="hljs-string">'react'</span>;
<span class="hljs-keyword">import</span> ReactDOM <span class="hljs-keyword">from</span> <span class="hljs-string">'react-dom'</span>;
<span class="hljs-keyword">import</span> App <span class="hljs-keyword">from</span> <span class="hljs-string">'./App'</span>;
<span class="hljs-keyword">import</span> { initializeFirebase } <span class="hljs-keyword">from</span> <span class="hljs-string">'./push-notification'</span>;

ReactDOM.render(<span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">App</span> /&gt;</span></span>, <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">'root'</span>));
initializeFirebase();
</code></pre>
<blockquote>
<p>You can find the keys to your project inside the <strong>Firebase Console.</strong></p>
</blockquote>
<p><img src="https://cdn-media-1.freecodecamp.org/images/yXHjfM1BfNm78YYVB1v14m7so7gfYEBqr0eX" alt="Image" width="1066" height="510" loading="lazy">
<em>Getting the keys</em></p>
<h4 id="heading-service-workers">Service Workers</h4>
<blockquote>
<p>A service worker is a script that your browser runs in the background, separate from the web page, enabling features that do not require a web page or user interaction.</p>
</blockquote>
<p>To receive the <strong>onMessage</strong> event, your app needs a service worker. By default, when you start Firebase, it looks for a file called <code>firebase-messaging-sw.js</code>.</p>
<p>But if you already have one and want to take advantage of it to receive notifications, you can specify during the Firebase startup which service worker it will use. For example:</p>
<pre><code class="lang-js"><span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> inicializarFirebase = <span class="hljs-function">() =&gt;</span> {
  firebase.initializeApp({
    <span class="hljs-attr">messagingSenderId</span>: <span class="hljs-string">'your messagingSenderId'</span>
  });

navigator.serviceWorker
    .register(<span class="hljs-string">'/my-sw.js'</span>)
    .then(<span class="hljs-function">(<span class="hljs-params">registration</span>) =&gt;</span> {
      firebase.messaging().useServiceWorker(registration);
    });
}
</code></pre>
<p>This service worker will basically import the script needed to show the notifications when your app is in the background.</p>
<p>We need to add <code>firebase-messaging-sw.js</code> to the location where your files are served. As I’m using the create-react-app, I’m going to add it inside the public folder with the following content:</p>
<pre><code class="lang-js">importScripts(<span class="hljs-string">'https://www.gstatic.com/firebasejs/4.8.1/firebase-app.js'</span>);
importScripts(<span class="hljs-string">'https://www.gstatic.com/firebasejs/4.8.1/firebase-messaging.js'</span>);

firebase.initializeApp({
    <span class="hljs-attr">messagingSenderId</span>: <span class="hljs-string">"your messagingSenderId again"</span>
});

<span class="hljs-keyword">const</span> messaging = firebase.messaging();
</code></pre>
<h3 id="heading-requesting-permission-to-send-notifications">Requesting permission to send notifications</h3>
<p>Well, everyone knows how annoying it is to enter the site and ask for authorization to send notifications. So let’s do it another way!<br>Let the user choose whether or not to receive notifications.</p>
<p>First of all, let’s create the function that will make the request and return the user’s token.</p>
<p>Inside our push-notification.js file, add the function:</p>
<pre><code class="lang-js"><span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> askForPermissioToReceiveNotifications = <span class="hljs-keyword">async</span> () =&gt; {
  <span class="hljs-keyword">try</span> {
    <span class="hljs-keyword">const</span> messaging = firebase.messaging();
    <span class="hljs-keyword">await</span> messaging.requestPermission();
    <span class="hljs-keyword">const</span> token = <span class="hljs-keyword">await</span> messaging.getToken();
    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">'token do usuário:'</span>, token);

    <span class="hljs-keyword">return</span> token;
  } <span class="hljs-keyword">catch</span> (error) {
    <span class="hljs-built_in">console</span>.error(error);
  }
}
</code></pre>
<p>We need to call this function from somewhere, so I’ll add it at the click of a button.</p>
<pre><code class="lang-js"><span class="hljs-keyword">import</span> React <span class="hljs-keyword">from</span> <span class="hljs-string">'react'</span>;
<span class="hljs-keyword">import</span> { askForPermissioToReceiveNotifications } <span class="hljs-keyword">from</span> <span class="hljs-string">'./push-notification'</span>;

<span class="hljs-keyword">const</span> NotificationButton = <span class="hljs-function">() =&gt;</span> (
    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">onClick</span>=<span class="hljs-string">{askForPermissioToReceiveNotifications}</span> &gt;</span>
      Clique aqui para receber notificações
    <span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span></span>
);

<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> NotificationButton;
</code></pre>
<p>Okay, let’s see it working:</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/khiSZEmyAt--sOXC1UbIYm4-GlPRI3WzBBg-" alt="Image" width="1066" height="559" loading="lazy"></p>
<h3 id="heading-sending-notifications">Sending notifications</h3>
<p>To send the notification, we need to make a request to the Firebase API informing it of the token the user will receive.</p>
<blockquote>
<p>In the examples below I use Postman, but you can do this from any other REST client.</p>
</blockquote>
<p>Basically, we need to make a POST request to <a target="_blank" href="https://fcm.googleapis.com/fcm/send">https://fcm.googleapis.com/fcm/send</a> by sending a JSON in the request body.</p>
<p>Below is the structure of the JSON that will be sent:</p>
<pre><code class="lang-json">{
    <span class="hljs-attr">"notification"</span>: {
        <span class="hljs-attr">"title"</span>: <span class="hljs-string">"Firebase"</span>,
        <span class="hljs-attr">"body"</span>: <span class="hljs-string">"Firebase is awesome"</span>,
        <span class="hljs-attr">"click_action"</span>: <span class="hljs-string">"http://localhost:3000/"</span>,
        <span class="hljs-attr">"icon"</span>: <span class="hljs-string">"http://url-to-an-icon/icon.png"</span>
    },
    <span class="hljs-attr">"to"</span>: <span class="hljs-string">"USER TOKEN"</span>
}
</code></pre>
<p>In the request header, we need to pass the server key of our project in Firebase and the content-type:</p>
<pre><code>Content-Type: application/json
<span class="hljs-attr">Authorization</span>: key=SERVER_KEY
</code></pre><blockquote>
<p>The server key is found in the project settings in the Firebase Console under the Cloud Messaging tab.</p>
</blockquote>
<p><img src="https://cdn-media-1.freecodecamp.org/images/RmPzmgbO2g2-9aexdELqtrpVyThMDDaMe4Mw" alt="Image" width="1066" height="540" loading="lazy"></p>
<h4 id="heading-notifications-in-action">Notifications in action</h4>
<blockquote>
<p>Remember that notifications will only appear when your app is minimized or in the background.</p>
</blockquote>
<p><img src="https://cdn-media-1.freecodecamp.org/images/ZCQkLJ-JT2iq1VXYSRjzio-tKEVdTEd6cSHl" alt="Image" width="1066" height="540" loading="lazy"></p>
<p>That is how we send a direct notification to a device.</p>
<h3 id="heading-send-notifications-to-a-group-of-users">Send notifications to a group of users</h3>
<p>Well, now that we’ve seen how to send a notification to one user, how do we send a notification to multiple users at once?</p>
<p>To do this, Firebase has a feature called <strong>topic</strong>, where you insert multiple tokens for a specific topic, and you can send the same notification to all of them from a single request.</p>
<h4 id="heading-how-to-do-this">How to do this</h4>
<p>We will basically send a POST request to the address <a target="_blank" href="https://iid.googleapis.com/iid/v1/TOKEN/rel/topics/TOPICO_NAME">https://iid.googleapis.com/iid/v1/<strong>TOKEN</strong>/rel/topics/<strong>TOPIC_NAME</strong></a>, passing the topic name and the token in the URL.</p>
<p>Do not forget to pass in the header the same authorization that we used to send the notification.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/SkEgziQtqdWRAY91Vqat-Pli8fqwYMLrni2q" alt="Image" width="1066" height="540" loading="lazy"></p>
<p>Sending the notification to users subscribed to any topic is very similar to sending a notification to a single user. The difference is that we need to pass the topic name in the <strong>“to”</strong> attribute instead of the token.</p>
<p>See the example below:</p>
<pre><code class="lang-json">{
    <span class="hljs-attr">"notification"</span>: {
        <span class="hljs-attr">"title"</span>: <span class="hljs-string">"Firebase"</span>,
        <span class="hljs-attr">"body"</span>: <span class="hljs-string">"Firebase topic message"</span>,
        <span class="hljs-attr">"click_action"</span>: <span class="hljs-string">"http://localhost:3000/"</span>,
        <span class="hljs-attr">"icon"</span>: <span class="hljs-string">"http://localhost:3000/icon.png"</span>
    },
    <span class="hljs-attr">"to"</span>: <span class="hljs-string">"/topics/TOPIC_NAME"</span>
}
</code></pre>
<p><img src="https://cdn-media-1.freecodecamp.org/images/NzN-fFuUxFDuNbMRd8e9-qGJsbZZPdZwGnn8" alt="Image" width="1066" height="540" loading="lazy"></p>
<h4 id="heading-conclusion">Conclusion</h4>
<p>Thanks for reading this! I hope you now understand how to make use of push notifications. The repository with the demo code can be found <a target="_blank" href="https://github.com/Leocardoso94/push-notification-demo">here</a>.</p>
<p>To get notified of my future posts, follow me on <a target="_blank" href="https://github.com/Leocardoso94">GitHub</a> or <a target="_blank" href="https://twitter.com/Leocardoso94_">Twitter</a>.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ Why your Push Notifications never see the light of day ]]>
                </title>
                <description>
                    <![CDATA[ By Neil Mathew Push Notifications fail on specific Android phones. Here’s why. I recently added support for Push Notifications in the Kayako App. I tested and shipped it. And I thought I did pretty good job. But then one by one, my users start commen... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/why-your-push-notifications-never-see-the-light-of-day-3fa297520793/</link>
                <guid isPermaLink="false">66c36779b737bb2ce707322f</guid>
                
                    <category>
                        <![CDATA[ android app development ]]>
                    </category>
                
                    <category>
                        <![CDATA[ androiddev ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Firebase ]]>
                    </category>
                
                    <category>
                        <![CDATA[ mobile app development ]]>
                    </category>
                
                    <category>
                        <![CDATA[ push notification ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Sat, 28 Oct 2017 18:55:46 +0000</pubDate>
                <media:content url="https://cdn-media-1.freecodecamp.org/images/1*1KfeXO-IedHQ9cUI83cV3g.jpeg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Neil Mathew</p>
<h4 id="heading-push-notifications-fail-on-specific-android-phones-heres-why">Push Notifications fail on specific Android phones. Here’s why.</h4>
<p>I recently added support for <a target="_blank" href="https://firebase.google.com/docs/cloud-messaging/">Push Notifications</a> in the <a target="_blank" href="https://play.google.com/store/apps/details?id=com.kayako.android.k5">Kayako App</a>. I tested and shipped it. And I thought I did pretty good job.</p>
<p>But then one by one, my users start commenting that the the app doesn’t show any notifications about 95% of the time. At first, I thought it was a mistake because the Push Notifications were working as intended on my emulator and devices. But as I dug deeper, it became clear how serious and valid this problem was. This was but the tip of the iceberg. Close to 50% of our Android app users were affected but only few informed us about it.</p>
<h3 id="heading-so-whats-the-problem">So, what’s the problem?</h3>
<p>Push Notifications are <strong>not</strong> working properly on specific Android phones.</p>
<p>I use the word ‘properly’ because users receive push notifications when the app is open but <a target="_blank" href="https://github.com/firebase/quickstart-android/issues/41">not when it is closed</a>, which defeats the purpose of push notifications.</p>
<p>I use the words ‘specific Android phones’ because this issue is noticed only on phones by manufacturers like Xiaomi, Oppo, One Plus, Vivo, Lenovo, Huawei, Samsung, and a few others.</p>
<h3 id="heading-why-is-this-happening-and-how-do-we-fix-it">Why is this happening and how do we fix it?</h3>
<p>To understand the problem, let’s first understand the Android UI and the expected behavior of Push Notifications.</p>
<p>On Android, we have three buttons at the bottom as part of the Navigation Bar. The square button, on click, opens the <strong>Recents</strong> screen. The <strong>Recents</strong> screen lists all the ongoing tasks or apps recently opened. We can clear these applications at any time, as shown below.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/VMda4Y0jAqWe3uv5jqChb4HzarB7g2ffPjU0" alt="Image" width="362" height="667" loading="lazy">
<em>Recents Screen</em></p>
<p>Yet on certain <a target="_blank" href="https://www.xda-developers.com/what-is-custom-rom-android/">stock ROMs</a> (Android operating system customized by device manufacturers), clearing an application kills that application and its background services. This is bad because we need background services to show Push Notifications.</p>
<p>When the server informs the Android device of a new Push Notification, it would normally re-start the application’s background services to show the notification to the user. That’s good because background services will automatically start to show push notifications.</p>
<p>The image below shows the expected behavior which is the case for vanilla ROMs. This is the original Android firmware that is not customized by manufacturers.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/vsgpo013XZS9sWzJO4yXmsRyZ7O8TsP8QinG" alt="Image" width="358" height="661" loading="lazy">
<em>Expected Push Notification Behavior</em></p>
<p>Yet despite this, some Android phones using the Kayako app are <strong>not</strong> receiving Push Notifications when the app is cleared from <strong>Recents</strong> screen. The reason is that phone manufacturers like Oppo, Xiaomi, and One Plus use a stock ROM that disables the re-starting of background services for most apps. This is bad because we’re back to where we started with no way to show Push Notifications.</p>
<p>Thankfully, these stock ROMs have a Settings page to enable the re-starting of background services. Although the auto-starting of background services are disabled by default, users can manually enable this feature by following some instructions. This is good because now background services can be automatically started to show Push Notifications. But, it’s an ugly solution because it involves some manual work that the user has to do.</p>
<p>The intentions of the manufacturers are to conserve battery and improve performance. The app users now have to open their settings app, navigate to the correct page, scroll through a list of apps, and then enable the feature for the Kayako app.</p>
<h4 id="heading-but-wait-why-dont-apps-like-gmail-and-slack-have-these-problems">But wait, why don’t apps like Gmail and Slack have these problems?</h4>
<p>Top-popular apps like Gmail, Slack and Whatsapp are whitelisted by these stock ROMs. That means these apps have auto-launch enabled for them by default.</p>
<p>However our app, along with many many others, have auto-launch disabled by default.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/m-OlwUJt4m7rnaN84273MxOWR5viXIcDORZr" alt="Image" width="751" height="787" loading="lazy">
<em>One Plus ‘Apps auto-launch’ Settings page</em></p>
<h4 id="heading-i-cant-find-the-settings-to-enable-auto-launch-where-are-they-located">I can’t find the settings to enable auto-launch. Where are they located?</h4>
<p>The steps to enable auto-launch for an app are different for different manufacturers. This is because this is not a native Android feature and is very specific to stock ROMs.</p>
<p>It should also be noted that the terminology used by each manufacturer is different. The auto-launch feature can be referred to as app auto-start, start-up manager, auto-start manager, app optimisation, protected apps, or background app management.</p>
<p>To make matters worse, the auto-launch settings page is not easy to find. For One Plus devices (using <a target="_blank" href="https://www.android.com/versions/nougat-7-0/">Nougat</a> or below), you need to open up Settings, click Apps, then the gear icon located on the toolbar, and then Apps Auto-launch under the Advanced sub-category at the very bottom.</p>
<h3 id="heading-alright-whats-the-solution">Alright, what’s the solution?</h3>
<p>In the end, the user will have to perform the steps manually. This can not be programmatically enabled for all devices. The best we can do is to make it as easy as possible for app users to do so.</p>
<h4 id="heading-create-a-support-article">Create a support article</h4>
<p><a target="_blank" href="https://www.freecodecamp.org/news/why-your-push-notifications-never-see-the-light-of-day-3fa297520793/undefined">Kelly O’Brien</a> and I wrote an article which makes an attempt to identify all the device manufacturers with this problem and explain the steps to enable Push Notifications on those devices. You can read about it <a target="_blank" href="https://support.kayako.com/article/1461-why-aren-t-push-notifications-working-on-my-android-app">here</a>.</p>
<h4 id="heading-inform-users-in-app">Inform users in-app</h4>
<p>As I mentioned before, not everyone takes the time out to complain. I can not expect users to contact the support team or search for the support article online. At the same time, there’s no easy way to automatically identify if Push Notifications aren’t working when the app is closed.</p>
<p>I decided to show a small footer on the Push Notifications Settings page where the article is available to the user at all times.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/t1U0ZBIa3qJG1hvdU1lQT9GO4tJg3N0q5JUY" alt="Image" width="437" height="771" loading="lazy">
<em>Push Notification Settings Page</em></p>
<h4 id="heading-open-the-concerned-settings-page-in-app">Open the concerned settings page in-app</h4>
<p>I’ve found many Stack Overflow answers like <a target="_blank" href="https://stackoverflow.com/questions/34149198/how-to-enable-auto-start-for-my-app-in-xiaomi-programmatically">this one</a> which recommend programmatically opening the concerned settings page by detecting your device manufacturer. While I like the idea, I have not implemented this. I haven’t had the chance to test if the device-specific code actually works which puts me at unease.</p>
<p>If you have other suggestions or ideas, I welcome them.</p>
 ]]>
                </content:encoded>
            </item>
        
    </channel>
</rss>
