Я пытаюсь отправить уведомление pu sh на мой телефон, когда я подключаюсь или отключаюсь от Wi-Fi с жестким кодом. Я не собираюсь использовать FireBase, он просто должен сказать, что вы были отключены или подключены.
Я смотрел в Интернете, но могу найти только примеры, которые используют FireBase
Как я могу сделать это просто жестко закодировано ?
app.component.ts
import { Component } from '@angular/core';
import { Platform, Events } from '@ionic/angular';
import { SplashScreen } from '@ionic-native/splash-screen/ngx';
import { StatusBar } from '@ionic-native/status-bar/ngx';
import { Network } from '@ionic-native/network/ngx';
import { NetworkProvider } from '../app/network-provider';
import { Push, PushObject, PushOptions} from '@ionic-native/push/ngx';
@Component({
selector: 'app-root',
templateUrl: 'app.component.html',
styleUrls: ['app.component.scss']
})
export class AppComponent {
constructor(
public platform: Platform,
public events: Events,
public network: Network,
public networkProvider: NetworkProvider,
private splashScreen: SplashScreen,
private statusBar: StatusBar,
private push: Push
) {
this.initializeApp();
}
initializeApp() {
this.platform.ready().then(() => {
this.statusBar.styleDefault();
this.splashScreen.hide();
this.push.hasPermission()
.then((res: any) => {
if (res.isEnabled) {
console.log('We have permission to send push notifications');
} else {
console.log('We do not have permission to send push notifications');
}
});
this.networkProvider.initializeNetworkEvents();
this.push.createChannel({
id: "notification",
description: "My first test channel",
importance: 3
}).then(() => console.log('Channel created'));
const options: PushOptions = {
android: {},
ios: {
alert: 'true',
badge: true,
sound: 'false'
},
windows: {},
browser: {
pushServiceURL: 'http://push.api.phonegap.com/v1/push'
}
}
const pushObject: PushObject = this.push.init(options);
// Offline event
this.events.subscribe('network:offline', () => {
alert('network:offline ==> '+this.network.type);
pushObject.on('notification').subscribe((notification: any) => console.log('Received a notification', notification));
console.log("Geen WIFI");
});
// Online event
this.events.subscribe('network:online', () => {
alert('network:online ==> '+this.network.type);
pushObject.on('notification').subscribe((notification: any) => console.log('Received a notification', notification));
console.log("Wel WIFI");
});
});
}
}
```