@lado wrote:
Hello,
Implementation below sends notification from my Google Firebase account Cloud Messaging to my app, but I’m looking for some useful example, how to push notification in
Ionic2Type ScriptAndroidapplication from one app to another :my Installs:
$ ionic cordova platform add android $ ionic cordova plugin add phonegap-plugin-push --variable SENDER_ID=my sender ID $ npm install --save @ionic-native/push
app.component.ts:import { Component, ViewChild } from '@angular/core'; import { Platform } from 'ionic-angular'; import { StatusBar } from '@ionic-native/status-bar'; import { SplashScreen } from '@ionic-native/splash-screen'; import { Push, PushObject, PushOptions } from '@ionic-native/push'; import { AlertController, Nav } from "ionic-angular"; import { HomePage } from '../pages/home/home'; import { DetailsPage } from '../pages/details/details'; @Component({ templateUrl: 'app.html' }) export class MyApp { @ViewChild(Nav) nav: Nav; rootPage: any = HomePage; constructor(platform: Platform, statusBar: StatusBar, splashScreen: SplashScreen, private push: Push, public alertCtrl: AlertController) { platform.ready().then(() => { statusBar.styleDefault(); splashScreen.hide(); this.initPushNotification(); }); } initPushNotification() { 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'); } }); const options: PushOptions = { android: { senderID: 'my sender ID' }, ios: { alert: 'true', badge: true, sound: 'false' }, windows: {} }; const pushObject: PushObject = this.push.init(options); pushObject.on('notification').subscribe((notification: any) => { console.log('Received a notification', notification); let confirmAlert = this.alertCtrl.create({ title: 'New Notification', message: JSON.stringify(notification), buttons: [{ text: 'Ignore', role: 'cancel' }, { text: 'View', handler: () => { this.nav.push(DetailsPage, { message: notification.message }); } }] }); confirmAlert.present(); }); pushObject.on('registration'). subscribe((registration: any) => console.log('Device registered', registration)); pushObject.on('error'). subscribe(error => console.error('Error with Push plugin', error)); } }details.ts:
import { Component } from '@angular/core'; import { IonicPage, NavController, NavParams } from 'ionic-angular'; @IonicPage() @Component({ selector: 'page-details', templateUrl: 'details.html', }) export class DetailsPage { pushMessage: string = 'message'; constructor(public navCtrl: NavController, public navParams: NavParams) { if (navParams.data.message) { this.pushMessage = navParams.data.message; } } ionViewDidLoad() { console.log('ionViewDidLoad DetailsPage'); } }Example or advice would be helpful
Posts: 1
Participants: 1