I have successfully implemented ngCordova local notifications, but now I am looking for a way to make it trigger for each individual

Is there a way to trigger a notification on every logged-in user's mobile device when a value is changed and saved in Firebase? Currently, I am able to send a local notification using ngCordova when a user enters text in an ionicPopup with textarea. How can I extend this functionality to notify all logged-in users?

Service:

servicesModule.factory("Profile", ["$firebaseObject",
  function($firebaseObject) {
    return function(new_value) {
      var ref = new Firebase("https://feedback-system.firebaseio.com/Courses/" + 'newValue');
      var new_value_ref = ref.child(new_value);
      return $firebaseObject(new_value_ref);
    }
  }
]);

Controller:

var ionicApp = angular.module('localNotificationModule', ['ionic', 'ngCordova']);

ionicApp.controller('localNotificationCtrl', ['$scope', '$rootScope', '$ionicPlatform', '$cordovaLocalNotification', '$state', 'Profile', '$firebase', 'Firebase', function($scope, $rootScope, $ionicPlatform, $cordovaLocalNotification, $state, Profile, $firebase, Firebase){

        $scope.profile = Profile("physicsmarie");

        // calling $save() on the synchronized object syncs all data back to our Firebase database
        $scope.testNotification = function() {
          $scope.profile.$save().then(function() {
            scheduleDelayedNotification($scope.profile.name);
          }).catch(function(error) {
            alert('Error!');
          });
        };

function scheduleDelayedNotification(newValue) {
    $ionicPlatform.ready(function () {
            $cordovaLocalNotification.schedule({
                id: 1,
                title: 'New Notification',
                text: newValue,
                autoCancel: true
            }).then(function (result) {
                alert("Notification Set");
            });
    });
    };
}]);

Answer №1

Great news, everything is now functional thanks to the following code:

firebaseRef.on('value', function(){
    implementing local notification scheduling
});

However, there are two issues that need to be addressed:

  1. Ensuring notifications are triggered on the message sender's end too.
  2. Resolving the notification failure when the app is in a 'background' state.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

A guide to building a versatile dropdown component with Material UI or MUI in a React application

Is there a way to create a reusable dropdown component using Material UI or MUI in React? ...

TS type defined by JS constants

I am currently working on a project that involves both JavaScript and TypeScript. I am trying to find a solution to reduce code duplication when using JavaScript string constants by converting them into TypeScript types. For example, let's say I have ...

How to Pass Values in handleChange Event in Typescript

I have noticed that most online examples of handling change events only pass in the event parameter, making the value accessible automatically. However, I encountered an error stating that the value is not found when trying to use it in my handleChange fun ...

Using an array as a data structure for a d3.js tree layout

I'm looking to use d3.js to create a diagram using the tree layout. Instead of the typical flare json structure with hierarchical children, I have an array representing different timesteps that I want to transform into a tree. My plan is to adjust the ...

Combing external JavaScript with React functionality

Hey there, I've been working on merging two projects that I came across recently: https://github.com/danxfisher/MeetEasier and this awesome page https://tympanus.net/Development/Interactive3DMallMap/ After making some changes in the MeetEasier React ...

Guide on extracting unique key values from an array by utilizing a different key

I have an array containing the names of products along with their storage capacities. let products = [{name: "samsung A", storage: "128GB"}, {name: "samsung B", storage: "128GB"}, {name: "samsung C", storag ...

Resolved issue with sticky header movement after scrolling event

I've been working on a sticky header code, but I'm having trouble achieving a smooth scroll transition. The fixed header seems to jump after just one scroll. Here is the basic HTML structure: <div class="headerWrapper"> <div id="to ...

The JSON data did not fully transfer into my AngularJS application

I wrote the code to display country details, but I am only getting partial information from the JSON. I am only able to fetch the country name and population in the output. Could there be an issue with the syntax? <!DOCTYPE HTML> <html ng-app= ...

Tips for transferring information from Django to React without relying on a database

Currently, I am in the process of developing a dashboard application using Django and React. The data for the user is being pulled from the Dynamics CRM API. To accomplish this, I have implemented a Python function that retrieves all necessary informatio ...

What is the best way to pass my request data to my $scope variable?

I'm currently facing a challenge with this particular topic. My goal is to add the response data that I retrieve from Express to my angular $scope and then direct the user to their profile page. This is how my Controller Function is structured: $sc ...

Differences in row padding when transitioning from Bootstrap 3 to Bootstrap 4

One thing I've noticed is that when utilizing Bootstrap 3, the use of div.row would automatically create a vertical spacing between rows which was quite appealing. However, upon transitioning to Bootstrap 4, this automatic spacing seemed to disappear. ...

The response body in Express is returned as a ReadableStream instead of the typical JSON format

When using Express to create an API endpoint, I typically respond with res.json() to send a JSON object in the response that can be consumed by the client. In my API, I am implementing batched promises, resolving them, and sending back an object. However ...

Interacting with iView UI dropdown menu items

I'm attempting to create a click event in iView ui. Here's my code: <DropdownMenu slot="list"> <DropdownItem @on-click="markAsRead">Mark as read</DropdownItem> </DropdownMenu> The function markAsRead isn't exec ...

Using Angular2 to assign the response from an http.get request to a class object

I am a beginner in Angular and I have a JSON file that holds the configuration URL for my application. Path: app/config/development.json { "apiUrl": "http://staging.domain.com:9000/", "debugging": true } Below is the content of my config.service.t ...

The functionality of sending form data via Express.js router is restricted

In my current project, I am developing a basic CRUD functionality in express. My goal is to utilize the express.Router() to transmit form data via the HTTP POST method. The form structure on the browser appears as follows: form.png The process was flawle ...

Can't seem to res.send using Express framework

Hello, I'm encountering an issue when trying to send a response using Express. I've seen suggestions in other questions that changing the variables err and res may resolve this problem, but it hasn't worked for me. router.post('/checkP ...

ApEditingError: The method editAp is not defined in _this.props

I am facing an issue while trying to invoke the function editAp located in the func.js file from Edit1.js. I have provided the code snippets below for better understanding: import firebase from "firebase"; if (!firebase.apps.length) { firebase.initializ ...

Discovering the value of a checkbox using jQuery and Ajax

I have a challenge with sending the state of multiple checkboxes on my page back to the database using ajax. While I am comfortable working with jquery and ajax for SELECT and OPTIONS elements, I am struggling to do the same for checkboxes and extracting t ...

What is the method to retrieve the information from a JSON response of a POST request in a Next/React application?

I am currently leveraging the Next.js API route to manage a POST request and subsequently send a response back to the frontend. To verify this process, I have utilized the Rapid API client extension and confirmed that a response is indeed being sent to the ...

JS | How can we make an element with style=visibility:hidden become visible?

HTML: <div id="msg-text"><p><b id="msg" name="msg" style="visibility:hidden; color:#3399ff;">This is a hidden message</b></p></div> JS: $('#url').on('change keyup paste', function() { $('# ...