ionic-team / capacitor

Build cross-platform Native Progressive Web Apps for iOS, Android, and the Web ⚡️
https://capacitorjs.com
MIT License
11.47k stars 977 forks source link

PushNotifications does not have web implementation. #1449

Closed idhard closed 5 years ago

idhard commented 5 years ago

Description of the problem:

getting "PushNotifications does not have web implementation." after the app is booted on android emulator, i'm loading the app from an external URL with the capacitor config variable:

"server": {
    "url":"https://MY-SITE.com"
 }
import { Plugins } from '@capacitor/core';

const { Device, PushNotifications } = Plugins;

class Notifications {
    notifications = [];
    constructor() {

        PushNotifications.register();
        PushNotifications.addListener('registration', (token) => {
          console.log('token ' + token.value);
        });
        PushNotifications.addListener('registrationError', (error) => {
          console.log('error on register ' + JSON.stringify(error));
        });
        PushNotifications.addListener('pushNotificationReceived', (notification) => {
          console.log('notification ' + JSON.stringify(notification));
          this.notifications.push(notification);
        });

        PushNotifications.addListener('pushNotificationActionPerformed', (notification) => {
          console.log('notification ' + JSON.stringify(notification));
          this.notifications.push(notification);
        });
    }

}

export default new Notifications();

Affected platform

OS of the development machine

Other information: i'm following the example https://github.com/jcesarmobile/ionic-angular-capacitor-push-example but instead of Angular i'm using React

Capacitor version: @capacitor/core@1.0.0-beta.19 node version: v11.14.0 npm version: 6.9.0

Related:

749 #1393

jcesarmobile commented 5 years ago

Does your web have Service Workers? looks like they prevent the Capacitor injector from working https://stackoverflow.com/questions/55894716/how-to-package-a-hosted-web-app-with-ionic-capacitor.

If not, it could be some problem with the bundler making the app use the web implementation instead of the native implementation

idhard commented 5 years ago

i'm using webpack with create-react-app but without services workers enabled , i will look into it , could you point where is the logic to detect the device type ? thanks

jcesarmobile commented 5 years ago

Try updating to beta 22, there was a bug preventing the Capacitor injection in https urls.

idhard commented 5 years ago

updating to beta 22 did the job, thanks! BTW is there a documentation on how to update Capacitor , currently just updating all related npm packages

jcesarmobile commented 5 years ago

Updating npm packages should be enough. Sometimes if we did changes in the templates you should do them too (but most times it’s just to update dependencies of the native libraries). At the moment we are not documenting those changes, once we release the final release we will do it.

mburger81 commented 5 years ago

@idhard does the pushNotificationReceived and pushNotificationActionPerformed events worked for you?

Not sure how that would work on with web. Having a look from documentation PushNotifictions plugin should work only for Android and ios?

We have the problem that the events pushNotificationReceived is never performed. Having a look to https://github.com/ionic-team/capacitor/blob/master/android/capacitor/src/main/java/com/getcapacitor/plugin/PushNotifications.java it seems this events are also not implemented?

jcesarmobile commented 5 years ago

Please, don’t use unrelated issues to ask questions. If you have questions we have a capacitor dedicated slack https://getcapacitor.herokuapp.com/ and forums https://forum.getcapacitor.com/ or even on stackoverflow using capacitor tag.

On beta 22 those both events should work fine