import { Component, OnInit } from ‘@angular/core’;
import { HomePage } from ‘./…/home/home.page’;
import { HttpClient } from ‘@angular/common/http’;
import { ToastController, AlertController, MenuController } from ‘@ionic/angular’;
import { Storage } from ‘@ionic/Storage’;
import { Router } from ‘@angular/router’;
import { Push, PushObject, PushOptions } from ‘@ionic-native/push/ngx’;
import { Device } from ‘@ionic-native/device/ngx’;
@Component({
selector: ‘app-giris’,
templateUrl: ‘./giris.page.html’,
styleUrls: [’./giris.page.scss’],
})
export class GirisPage implements OnInit {
userdata: any;
regID: any;
pushregid: any;
dbregID: any;
deviceid: any;
devmodel: any;
devserial: any;
devversion: any;
dplatform: any;
constructor(
private http: HttpClient,
public toastController: ToastController,
private storage: Storage,
public alertCtrl: AlertController,
private router: Router,
private menuCtrl: MenuController,
private push: Push,
private device: Device) {
}
ngOnInit() {
console.log(‘ngOnInit GirisPage’);
this.menuCtrl.swipeEnable(false);
this.menuCtrl.enable(false);
this.logForm();
}
data = {}
apiUrl=‘http://192.168.1.91:8080/mobilbks/’;
logForm() {
let newData = {
funcion: ‘logForm’,
data: this.data
}
//console.log(this.data);
this.http.post(this.apiUrl, JSON.stringify(newData)).subscribe(data => {
if (data[‘success’] === “Login Success”) {
this.storage.set(‘session_storage’, data[‘res’]);
let newDevice = {
funcion: ‘newDevice’,
data: this.data,
deviceID: this.device.uuid,
devmodel: this.device.model,
devserial: this.device.serial,
devversion: this.device.version,
dplatform: this.device.platform,
dbregID: this.pushSetup()
}
console.log(newDevice);
this.http.post(this.apiUrl, JSON.stringify(newDevice)).subscribe(data => {
this.deviceid = data;
console.log(this.deviceid);
});
this.router.navigateByUrl(‘menu’);
} else {
this.girishataAlert();
this.router.navigateByUrl(‘giris’);
}
},
(err) => {
console.log(err);
});
}
async girishataAlert() {
const alert = await this.alertCtrl.create({
header: ‘Hatalı Giriş’,
message: ‘Lütfen Kullanıcı Bilgilerinizi Kontrol Ediniz’,
buttons: [‘Tamam’]
});
await alert.present();
}
pushSetup() {
const options: PushOptions = {
android: {
senderID: ‘11111111111111’
},
ios: {
alert: ‘true’,
badge: true,
sound: ‘false’
}
};
const pushObject: PushObject = this.push.init(options);
pushObject.on('registration').subscribe((data: any) => {
//alert('Device token/handle is: ' + data.registrationId);
this.regID = **data.registrationId**;
});
}
}
Hi, I want save the device registrationID (this.regID) to mysql database.
but I can’t call the method
please help me