Я работаю в приложении ionic 3, где -:
объяснение -: 1. Я работаю над приложением ionic, в котором я пытаюсь интегрировать PUSH-уведомление в майское приложение с использованием firebase
Iвыполнили все шаги из https://ionicframework.com/docs/native/push/
Проблема: Push-уведомление не работает для веб-платформы для iOS и Android, оно работает.
**
Пожалуйста, смотрите: может быть, я неправильно ввожу fcm, так как ионный fcm не поддерживается для веб-сайтов.
**
Я помещаю код ниже:
ts file -:
import { Push, PushOptions , PushObject } from '@ionic-native/push/ngx';
export class MyApp {
rootPage:any = TabsPage;
fcmId: any;
constructor( private storage: Storage , private alertCtrl: AlertController , private push: Push , public navCtrl: NavController , platform: Platform, statusBar: StatusBar, splashScreen: SplashScreen) {
platform.ready().then(() => {
// Okay, so the platform is ready and our plugins are available.
// Here you can do any higher level native things you might need.
statusBar.styleDefault();
splashScreen.hide();
});
}
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 { AngularFireModule } from 'angularfire2';
import firebase from 'firebase';
import { AngularFireAuth } from 'angularfire2/auth';
import { AngularFireAuthModule } from 'angularfire2/auth'
import { Push } from '@ionic-native/push/ngx';
export const firebaseConfig = {
apiKey: "AIzaSyBrU5I4_hK-M4Ai3#############",
authDomain: "primeval-wind-230006.firebaseapp.com",
databaseURL: "https://primeval-wind-230006.firebaseio.com",
projectId: "primeval-wind-230006",
storageBucket: "primeval-wind-230006.appspot.com",
messagingSenderId: "##########"
}
firebase.initializeApp(firebaseConfig)
@NgModule({
declarations: [
MyApp,
AboutPage,
ContactPage,
HomePage,
TabsPage,
SecondtryPage
],
imports: [
BrowserModule,
IonicModule.forRoot(MyApp),
AngularFireModule.initializeApp(firebaseConfig),
AngularFireAuthModule,
IonicStorageModule.forRoot()
],
bootstrap: [IonicApp],
entryComponents: [
MyApp,
AboutPage,
ContactPage,
HomePage,
TabsPage,
SecondtryPage
],
providers: [
StatusBar,Push,
SplashScreen,
{provide: ErrorHandler, useClass: IonicErrorHandler},
GooglePlus
]
})
export class AppModule {}