问题
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
I have followed all the steps from https://ionicframework.com/docs/native/push/
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