The phonegap-plugin-push does not successfully register

Currently, I am delving into the realm of app development using Phonegap and experimenting with the Phonegap push plugin available here. I am encountering an issue where the register event fails to fire even after initialization. Here are the steps I have taken:

  • Created the project using Phonegap
  • Installed the plugin following the provided instructions using
    phonegap plugin add phonegap-plugin-push --variable SENDER_ID="XXXXXXX"
  • Built the platform with phonegap build android

After adding the Android platform without any errors, the registration event does not trigger upon running the app. Here is a snippet of my code:

var app = {
    // Application Constructor
    initialize: function() {
        this.bindEvents();
    },
    // Bind Event Listeners
    //
    // Bind any events that are required on startup. Common events are:
    // 'load', 'deviceready', 'offline', and 'online'.
    ...
    // Additional code omitted for brevity
    ...
};

In my index.html file, the scripts are referenced as follows:

<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" src="js/push.js"></script>
<script type="text/javascript" src="js/index.js"></script>

Could there be an error in my setup? How can I confirm if the plugin is initializing correctly or why the registration event is not being triggered?

Answer №1

Insert this code snippet into your app:

// Update DOM on a Received Event
receivedEvent: function(id) {
    var push = PushNotification.init({
       "android": {
           "senderID": "XXXXXXX"
       },
        "ios": {"alert": "true", "badge": "true", "sound": "true"}, 
       "windows": {} 
   });
push.on('registration', function(data) {
    alert("registration event");
    alert(data.registrationId)
    console.log(JSON.stringify(data));
});

push.on('notification', function(data) {
    alert("notification event");
    console.log(JSON.stringify(data));

    push.finish(function () {
        console.log('finish successfully called');
    });
});

push.on('error', function(e) {
    alert("push error");
    alert(e);
});
alert('hello')

within the

onDeviceReady: function() {
    app.receivedEvent('deviceready');

}

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

After submitting the form, Axios sends multiple requests simultaneously

Recently, I embarked on a small project that involves using Laravel and Nuxt Js. The main objective of the project is to create a form for adding users to the database. Everything seems to be progressing smoothly, but there's a minor issue that I&apos ...

Having trouble installing npm package in Angular project

After cloning my project from GitLab, I encountered an issue while trying to install the NPM packages. When I ran npm install, an error popped up: https://i.stack.imgur.com/WNT5s.png Upon checking the log file, I found the following error message: 3060 ...

Date Object Replacement Error: "this is not a valid Date object."

For my web application, I require a specific date value. I attempted to modify the Date prototype, but encountered an issue with Jquery Date recognizing it. InitDate = Date; InitDate.prototype = Date.prototype; Date = function () { if (arguments.leng ...

`Encountering an unknown index while using AJAX to retrieve data from a PHP file

When using AJax to call a PHP file and retrieve values, I encountered an issue where the called PHP file returns an unidentified variable upon submission. Here is the script being used: <script> function showPrice(str) { if (str == "") { ...

The contents of Ionic views are not stored in a cache, so the controller must

In my ionic application, I have several views. When I launch the app, it takes me to the main view where data is loaded upon initialization of the controller. The issue arises when I navigate away from this view using tabs; sometimes the controller gets d ...

Distinguishing ft.remove() from popBackStack() in Android

I am attempting to eradicate a fragment from my stack. The following code snippet is what I have been employing: FragmentManager fm = getSupportFragmentManager(); if (fm != null) { FragmentTransaction ft = fm.beginTransaction(); Fragme ...

Dynamics of Rails and the power of jQuery with ajaxStop

For my Rails 5.2 project, I have included the gems 'jquery-rails' and 'jquery-ui-rails'. I am attempting to utilize the .ajaxStop( handler ) handler as outlined in the documentation found here: https://api.jquery.com/ajaxStop/#ajaxStop ...

Tips for preventing the loss of ajax calls when an Oauth access-token expires

As the creator of a JavaScript browser application (SPA) that communicates with a server protected by OAuth 2, I encounter the challenge of using short-lived access tokens and longer-lived refresh tokens. While this specific scenario involves my own server ...

Expanding angularjs date filter to support additional date formats

When working with Angularjs, you can utilize the Date Filter to format dates. Is there a way to get the date in the format outlined below? dd(st || nd || th) mm yyyy 1st May 2014 1<sup>st</sup> May 2014 Should I develop a new custom filter fo ...

Steps for integrating Cordova-vk plugin into an Ionic 3 project

I am looking to incorporate the cordova-vk plugin into my app, but I am having trouble connecting it to Typescript. vkSdk is not defined I understand that the plugin is located in the node_modules folder. How can I successfully integrate it into my page ...

The React Component in Next.js does not come equipped with CSS Module functionality

I have been attempting to incorporate and apply CSS styles from a module to a React component, but the styles are not being applied, and the CSS is not being included at all. Here is the current code snippet: ./components/Toolbar.tsx import styles from & ...

Tips on how to retrieve the value of a number-type input within a custom attribute directive

I have successfully implemented this code in IE 11, but now we are looking to transition away from IE11 and address some of the issues that have arisen. <input type="number" evaluate-input="model.personalNumber" ng-model="model ...

Synchronizing two navigation menus on a single-page application website

Let me start by saying that I specialize in back end development and am facing a specific challenge with building a website that includes two navigation menus. The main navigation menu features links like Home, while the sub-navigation menu includes option ...

How can I replicate the functionality of a div mimicking a select element using javascript upon clicking away from the element?

My task was to design a pseudo-select element that showcases columns for each row within the select. Due to HTML's restriction on allowing the <option> tag to include HTML, I had to find an alternate solution. One issue I encountered was replic ...

observing the value of the parent controller from the UI router state's resolve function

I am facing an issue in my AngularJS application while using ui-router. There are three states set up - the parent state controller resolves a promise upon a successful request, and then executes the necessary code. In the child state portfolio.modal.pate ...

Disabling the search function when it is clicked (before any actions are taken)

I've recently implemented a search form on my website, where the search field opens up upon clicking the search icon.https://i.stack.imgur.com/UeErx.png To make the search icon clickable, I disabled the search function. var $searchBtn = $search.find ...

What is the method for adjusting the width of a v-card based on its height?

I have a changing number of v-cards that are displayed based on their quantity. My goal is to maintain an aspect ratio of 16/9, but only adjust the width. To achieve this, I believe I need to make the width dependent on the height, although I am unsure ho ...

Tips on identifying HTML email input validation using JavaScript?

Just like when you can determine whether an input element with a required attribute was successfully validated, try using the following code: if($('input[type="email"]').val() && $('input[type="email"]').val().includes('@') & ...

Dynamic dropdown menu based on the location using JSON and jQuery

I need to create a series of dropdown menus for selecting country, state, and city. The country and state dropdowns are working fine, but I am having trouble populating the city dropdown. What could be missing in my code? Here is what I have so far: <f ...

Tips on retrieving an item using jQuery's select2 plugin

How can I retrieve the value (flight_no) from the processResults function in order to populate the airline name with the respective flight number when selected? I've attempted to access the (flight_no) within the processResults function, but I'm ...