我在我的Ionic 4项目中建立了一个小的警报服务(Angular AlertController的包装器),当我在 "ionic serve"(浏览器)、"ionic cordova emulate"(在我连接的手机上)、"ionic cordova build android"(在我的手机上手动安装app-debug APK)中查看项目时,它可以完美地工作,但是当我使用 "ionic cordova build android --prod --release "建立应用程序的发布版本时,警报的 "消息 "部分没有显示。头部(标题)和按钮仍然显示和工作正常,但信息没有出现。
这是我创建和显示警报的方法。
/**
* "Confirm" with callback or "Cancel" alert
*/
async confirmOrCancelAlert(title, message, callback) {
const alert = await this.alertController.create({
header: title,
message: message,
buttons: [
{
text: 'Cancel',
role: 'cancel',
cssClass: 'secondary',
}, {
text: 'Confirm',
handler: () => {
callback();
}
}
]
});
await alert.present();
}
这是调用上图所示方法的代码,它是通过点击按钮调用的。
/**
* Answer questions button event click
*/
answerQuestions() {
if (this.shift.getEarly() && (this.shift.getTimeToStart().asHours() > environment.alertTimes.answerQuestions)) {
var timeTo = this.durationFormatPipe.transform(this.shift.getStart());
var message = 'Your shift starts ' + timeTo + ', are you sure you want to answer questions now?';
this.alertService.confirmOrCancelAlert('You are early!', message, () => {
this.doAnswerQuestions();
});
} else {
this.doAnswerQuestions();
}
}
这里有两张图片,显示了发布版构建中的消息混乱,但在service emulate debug builds中显示出来。
非常感谢所有的建议。
我想这是一个时间问题。当你调用confirmOrCancelAlert()时,时间到(timeTo)还没有准备好,所以消息的类型将是未定义的。
试试这个。
answerQuestions() {
if (this.shift.getEarly() && (this.shift.getTimeToStart().asHours() > environment.alertTimes.answerQuestions)) {
var timeTo = this.durationFormatPipe.transform(this.shift.getStart());
var message = 'Your shift starts ' + timeTo + ', are you sure you want to answer questions now?';
setTimeout(() => {
this.alertService.confirmOrCancelAlert('You are early!', message, () => {
this.doAnswerQuestions();
});
}, 50);
} else {
this.doAnswerQuestions();
}
}
试试这个
async confirmOrCancelAlert(title, myMessage, callback) {
const alert = await this.alertController.create({
header: title,
message: myMessage,
buttons: [
{
text: 'Cancel',
role: 'cancel',
cssClass: 'secondary',
}, {
text: 'Confirm',
handler: () => {
callback();
}
}
]
});
await alert.present();
}
把名字改成 myMessage 以使其与物业名称不同。message: message
会造成一个问题,我想我去年也有同样的问题.检查一下,并告知我结果。