问题描述
我尝试将onesignal Playerid保存到存储中。我在下面使用此代码;
window["plugins"].Onesignal.getIds(function(ids) {
console.log(ids.userId);
this.storage.set('player_storage',ids.userId);
});
我可以使用此代码获取玩家ID并在控制台上显示。但是,当我尝试将playerid保存到存储中时,会出现此错误。
未捕获的TypeError:无法读取null的属性“存储”
PS:我曾经尝试过将数据发布到PHP,但是我也遇到了同样的错误。我的意思是任何动作都会返回此错误。
我需要有关此的帮助。
Login.ts的完整代码;
import { Component } from '@angular/core';
import { IonicPage,NavController,NavParams } from 'ionic-angular';
import { PostProvider } from '../../providers/post-provider';
import { Storage } from '@ionic/storage';
import { RegisterPage } from '../register/register';
import { HomePage } from '../home/home';
import { AlllogoutPage } from '../alllogout/alllogout';
import { Device } from '@ionic-native/device';
/**
* Generated class for the LoginPage page.
*
* See https://ionicframework.com/docs/components/#navigation for more info on
* Ionic pages and navigation.
*/
@IonicPage()
@Component({
selector: 'page-login',templateUrl: 'login.html',})
export class LoginPage {
login_username: string = "";
login_password: string = "";
login_error_msg: any;
userdevicename: any;
userdevicemodel: any;
userdevicemanufacturer: any;
login_player_id: any;
loggedplayers: any = [];
constructor(public navCtrl: NavController,public navParams: NavParams,private postPvdr: PostProvider,public storage: Storage,public device: Device) {
this.userdevicename = this.device.uuid;
this.userdevicemodel = this.device.model;
this.userdevicemanufacturer = this.device.manufacturer;
}
ionViewDidLoad() {
console.log('ionViewDidLoad LoginPage');
console.log('Device UUID is: ' + this.device.isVirtual);
}
gotoreg() {
this.navCtrl.push(RegisterPage);
}
alllogout() {
this.navCtrl.push(AlllogoutPage,{loginkey: this.login_username});
}
addlogin() {
if(this.login_username==""){
this.login_error_msg = "4";
}
else if(this.login_password==""){
this.login_error_msg = "5";
}
else {
let body = {
login_username: this.login_username,login_password: this.login_password,login_device: this.userdevicename,login_device_model: this.userdevicemodel,login_device_marka: this.userdevicemanufacturer,logdatas: 'do_login'
};
this.postPvdr.postData(body,'http://www.website.com/login.PHP').subscribe((data) =>{
var alertBox = data.msg;
if (data.success) {
var notificationopenedCallback = function(jsonData) {
console.log('notificationopenedCallback:' + JSON.stringify(jsonData));
};
window["plugins"].Onesignal
.startinit("xxx","xxx")
.handleNotificationopened(notificationopenedCallback)
.endInit();
window["plugins"].Onesignal.getIds(function(ids) {
console.log(ids.userId);
});
this.storage.set('session_storage',data.result);
this.navCtrl.setRoot(HomePage);
this.login_error_msg = "6";
}
else {
this.login_error_msg = alertBox;
}
});
}
}
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)