IOS首次安装网络授权后白屏问题处理方案:
pages.json第一个页面onLoad()加以下代码:
containerId 绑定到第一个view标签上
uni.getSystemInfo({
success: (res) => {
if (res.platform == 'ios') {
this.$nextTick(function() {
const query = uni.createSelectorQuery().in(this);
var isRecovery = true;
query.select('#containerId').boundingClientRect(data => {
isRecovery = false;
})
.exec();
var timer = setTimeout(() => {
if (isRecovery) {
plus.runtime.restart()
clearTimeout(timer)
timer = null;
}
}, 800)
})
}
}
})
页面引入fu-notwork组件
fu-notwork组件页面代码: created、 methods方法修改
<script>
created() {
let _this = this;
uni.getSystemInfo({
success: (res) => {
console.log(res.platform, 'platformplatform')
_this.platform = res.platform;
}
})
// 监听网络状态的变化
uni.onNetworkStatusChange(res => {
// console.log(res)
this.isConnected = res.isConnected;
if (this.isConnected) {
if (!uni.getStorageSync('CommonNetConnected') && _this.platform == 'ios') {
uni.setStorageSync('CommonNetConnected', true)
setTimeout(() => {
plus.runtime.restart()
}, 1000)
} else {
uni.setStorageSync('CommonNetConnected', true)
}
this.$emit('retry', {
msg: this.i18n['网络链接成功'],
networkType: res.networkType
});
} else {
if (this.mode == 'toast') {
this.$message.info(this.tips);
}
}
});
this.getNetworkStattus();
},
methods: {
// 功能:获取当前网络状态
getNetworkStattus() {
uni.getNetworkType({
success: res => {
// console.log(res.networkType);
if (res.networkType == 'none') {
this.isConnected = false;
switch (this.mode) {
case 'modal':
this.$util.showModal({
title: '提示',
content: this.tips
});
break;
case 'toast':
this.$message.info(this.tips);
break;
default:
this.$message.info({
content: this.i18n['无网络链接'],
position: 'top'
});
break;
}
} else {
this.isConnected = true;
if (!uni.getStorageSync('CommonNetConnected')) {
uni.setStorageSync('CommonNetConnected', true)
setTimeout(() => {
plus.runtime.restart()
}, 1000)
}
this.$emit('retry', {
msg: this.i18n['网络链接成功'],
networkType: res.networkType
});
}
}
});
}
}
};
</script>