dpa99c / cordova-plugin-firebasex

Cordova plugin for Google Firebase
MIT License
571 stars 467 forks source link

window.FirebasePlugin is not defined #146

Closed gareth-johnstone closed 5 years ago

gareth-johnstone commented 5 years ago

Hi guys, it could be that im going about this all wrong - and sorry i know this is the wrong style of issue for what im asking, but i couldnt find the "im probably being stupid, can you help a guy out", issue type

I currently have a Progressive Web App (PWA) (hosted on a server) that I'm pointing my cordova app at - in the PWA im putting the window.FirebasePlugin but its showing as undefined

Is this because its not available there and instead only available to the local content - if so, any way around this so i can pass the token back to my webapp?

Bug report

Current behavior:

window.firebaseapp is undefined

Expected behavior: window.firebaseplugin is available in my progressive web app

Steps to reproduce:

Screenshots

Environment information

Runtime issue

Android build issue:

iOS build issue:

Related code:

insert any relevant code here such as plugin API calls / input parameters

Console output

console output ``` // Paste any relevant JS/native console output here ```


**Other information:**
bipoza commented 5 years ago

I understand that this plugin only has support for Android and iOS, but it is possible to combine it with web technology. In my case using ionic I have detected the platform and launched the web or cordova method. https://firebase.google.com/docs/cloud-messaging/js/client

You have a great tutorial about Ionic PWA and Web Push Notifications https://medium.com/@david.dalbusco/add-web-push-notifications-to-your-ionic-pwa-358f6ec53c6f

import { Platform } from '@ionic/angular';
import {firebase} from '@firebase/app';

@Component({...})
export class MyPage {
  constructor(public platform: Platform) {
 if(platform.is('pwa'){
     if (firebase.messaging.isSupported()) {
         const messaging = firebase.messaging();
         await messaging.requestPermission();
         const token = await messaging.getToken();
         console.log('User token: ', token);
       } else {
           alert("Your browser is not supported");
       }
 }else{
  //Cordova plugin function
  window.FirebasePlugin.getToken(function(token) {
    // save this server-side and use it to push notifications to this device
    console.log(token);
   }, function(error) {
    console.error(error);
   });
 }
}
}

I hope I've helped!

gareth-johnstone commented 5 years ago

I created a index.html in xcode and i can get the push notifications to work if i have my files local to the app (so in the www folder in xcode)

However, none of the push notification code works on the hosted application that i want to have my cordova app pointed to. (window.firebaseplugin is undefined in that instance

So im at a loss as to how to get IOS push notifications in my cordova app that points to a PWA that is hosted on a server.

dpa99c commented 5 years ago

@gareth-johnstone this plugin is designed to support Cordova apps running on a native Android or iOS platform so your requirement to have a hosted PWA access the plugin API is beyond the scope of what this plugin is intended for.