phonegap / phonegap-plugin-push

Register and receive push notifications
MIT License
1.94k stars 1.91k forks source link

Push is not defined #2702

Open viniciusbarbosa opened 5 years ago

viniciusbarbosa commented 5 years ago

Hello! Good night! I would like your help.

Angular CLI: 6.0.0
Node: 8.11.1
Angular: 5.0.3
TypeScript: 2.7.2
NPM: 5.6.0
Cordova: 8.0.0 
Ionic: 3.20.0
Cordova Android: 7.1.4
Cordova IOS: 4.5.4
@ionic/app-scripts: 3.2.2

I have an app in Angular 5 with Ionic 3, and I'm trying to use notifications with the phonegap-plugin-push plugin, initially only for ANDROID. The project correctly executes both in the browser (ionic serve) and in android (--release and --prod) It also successfully completes the ionic: build --prod. But notifications do not work as expected.

As soon as the first step, which is to verify that the app has permission for Push Notification, already returns an error, described below.

I'm trying to use this plugin: https://ionicframework.com/docs/native/push

I already registered in firebase, copied the key, downloaded and put the file google-services.json

Module:

import { Push } from '@ionic-native/push/ngx';
...
providers: [Push]

Page:

import { Push, PushObject, PushOptions } from '@ionic-native/push/ngx';
...
constructor(
        private push: Push,
        private platform: Platform
) {}
...
if (this.platform.is('android')) {
    this.push.hasPermission().then((response) => {
        if (response.isEnabled) {
            console.log('notificacao','permissao');
        } else {
            console.log('notificacao', 'sem permissao');
        }
    }).catch(erro => {
        console.log('ERRO push hasPermission', erro);
    });
}

Package.json

...
"phonegap-plugin-push": {
        "SENDER_ID": "XXXXXXXXXXX",
        "ANDROID_SUPPORT_V13_VERSION": "27.+",
        "FCM_VERSION": "11.6.2"
}

Config.xml

...
<plugin name="phonegap-plugin-push" spec="^2.2.3">
        <variable name="SENDER_ID" value="XXXXXXXXXXX" />
</plugin>

When I run ionic cordova run android --device --debug orionic serve and enter the page with notification code, I saw that nothing happened. Do not even catch.

Accessing the browser's browser mode, putting breakpoint and browsing methods, I realized that:

1) this.push na página onde é chamado tem o seguinte valor:

Push {}
__proto__: IonicNativePlugin
constructor: ƒ Push()
createChannel: ƒ (channel)
deleteChannel: ƒ (id)
hasPermission: ƒ ()
init: ƒ (options)
listChannels: ƒ ()
__proto__: Object

2) Pressing F11, in the hasPermission () method you have: Push.prototype.hasPermission = function () { return cordova(this, "hasPermission", {}, arguments); };

3) Passing the mouse over the 'Push.prototype.hasPermission', I find the error:

Uncaught ReferenceError: Push is not defined
    at eval (eval at Push.hasPermission (index.js:39), <anonymous>:1:1)
    at Push.hasPermission (index.js:39)
    at new ListagemPropostasPage (listagem-propostas.ts:81)
    at createClass (core.js:12174)
    at createDirectiveInstance (core.js:12011)
    at createViewNodes (core.js:13449)
    at createRootView (core.js:13339)
    at callWithDebugContext (core.js:14740)
    at Object.debugCreateRootView [as createRootView] (core.js:14041)
    at ComponentFactory_.create (core.js:10960)

I've already tried on a real device and the error persists. And from there, I can not go on. Push not being set, it will not allow me to move forward.

Can you help me?

Sorry my english ...

Thank you

pratapnirala commented 4 years ago

I am also facing the same issue, any luck?