Ionic phonegap-plugin-push is not working for web

怎甘沉沦 提交于 2019-12-10 22:28:29

问题


How do I add my Web API key for Google Firebase? in my ionic app for web platform**

explanation -: 1. I am working on ionic App where I am trying to integrate it with PUSH (https://ionicframework.com/docs/native/push/) using firebase

  1. I have followed all the steps from https://ionicframework.com/docs/native/push/

  2. Problem: Push notification is not working for web platform for ios and android it is working .

I am putting the code below :

ts file -:

    import { Push, PushObject, PushOptions } from '@ionic-native/push';

    constructor(private push: Push) { }

          initPushNotification() {
            // to check if we have permission
            this.push.hasPermission().then((res: any) => {
              if (res.isEnabled) {
                console.log('We have permission to send push notifications');
              } else {
                console.log("We don't have permission to send push notifications");
              }
            });

            // to initialize push notifications
            const options: PushOptions = {
              android: {
                senderID: '839584699716',
              },
              ios: {
                alert: 'true',
                badge: true,
                sound: 'false',
              },
              windows: {},
              browser: {
                pushServiceURL: 'http://push.api.phonegap.com/v1/push',
              },
             };

    const pushObject: PushObject = this.push.init(options);

    pushObject.on('notification').subscribe((notification: any) => {
      console.log('Received a notification', notification);
      //Notification Display Section
      let confirmAlert = this.alertCtrl.create({
        title: 'New Notification',
        message: JSON.stringify(notification),
        buttons: [
          {
            text: 'Ignore',
            role: 'cancel',
          },
          {
            text: 'View',
            handler: () => {
              //TODO: Your logic here
              //self.nav.push(DetailsPage, {message: data.message});
            },
          },
        ],
      });
      confirmAlert.present();
      //
    });
    pushObject.on('registration').subscribe((registration: any) => {
      console.log('Device registered', registration);
      this.fcmId = registration.registrationId;
      console.log(this.fcmId);
      this.storage.set('fcmId', this.fcmId);
    });

    pushObject.on('error').subscribe(error => console.error('Error with Push plugin.....', error));
  }

app.module.ts

import { Push } from '@ionic-native/push';


import {AngularFireModule} from 'angularfire2';
import {AngularFireAuthModule} from 'angularfire2/auth';

import firebase from 'firebase';

export const firebaseConfig = {
  apiKey: "###############################",
  authDomain: "premier11-109eb.firebaseapp.com",
  databaseURL: "https://premier11-109eb.firebaseio.com",
  projectId: "premier11-109eb",
  storageBucket: "premier11-109eb.appspot.com",
  messagingSenderId: "########" 
}
firebase.initializeApp(firebaseConfig);

@NgModule({
  declarations: [
    MyApp,
   // ContentDrawer
    // HomePage
  ],
  imports: [
    HttpClientModule,
    FormsModule,
    MbscModule,
    BrowserModule,

    AboutusPageModule,
    AllcontestPageModule,
    CaptainselectionPageModule,
    CashcontestPageModule,
    CreateteamPageModule,
    ContestsPageModule,
    FairplayPageModule,
    HelpdeskPageModule,
    HomePageModule,
    JoinedpagePageModule,
    LegalityPageModule,
    LoginmobilePageModule,
    LoginwebPageModule,
    MatchcenterPageModule,
    NotificationPageModule,
    OtpverificationloginPageModule,
    PayPageModule,
    PaymentPageModule,
    PaymentgatewayPageModule,
    PlayerdetailsPageModule,
    PrivacypolicyPageModule,
    ProfilePageModule,
    SignupPageModule,
    TabsPageModule,
    TeamselectionPageModule,
    ViewteamPageModule,
    ErrorPageModule,
    FeedbackformPageModule,

    HttpModule,

    IonicModule.forRoot(MyApp),
    IonicStorageModule.forRoot(),
    AngularFireAuthModule,
    AngularFireModule.initializeApp(firebaseConfig)
  ],
  bootstrap: [IonicApp],
  entryComponents: [MyApp],
  providers: [
    StatusBar,
    SplashScreen,
    Camera,
    { provide: ErrorHandler, useClass: IonicErrorHandler },
    SharedsecondProvider,
    EmailComposer,
    SocialSharing,
    P11dataProvider,Push,GooglePlus,Facebook,Network,AndroidPermissions,
  ],
})
export class AppModule {}

来源:https://stackoverflow.com/questions/53680093/ionic-phonegap-plugin-push-is-not-working-for-web

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!