IOS首次安装网络授权后白屏问题处理方案

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>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
iOS上,应用程序在第一次启动时需要用户授权网络访问权限。如果用户没有授权网络访问权限,可能会导致应用程序无法正常启动,出现白屏等问题。为了解决这个问题,您可以在应用程序启动时请求网络访问权限,并在用户授权后再加载应用程序。 具体的做法如下: 1. 在应用程序启动时,检查网络访问权限是否已经授权。您可以使用uni-app提供的API:uni.getSetting()来检查网络权限状态,示例代码如下: ```javascript uni.getSetting({ success: function(res) { // 如果已经授权,则加载应用程序 if (res.authSetting['scope.userInfo']) { // 加载应用程序 // ... } // 如果未授权,则请求网络访问权限 else { uni.authorize({ scope: 'scope.userInfo', success() { // 用户授权成功,加载应用程序 // ... }, fail() { // 用户拒绝授权,提示用户并退出应用程序 uni.showModal({ title: '提示', content: '您拒绝了网络访问权限,无法使用本应用程序', showCancel: false, complete() { uni.navigateBack({ delta: 1 }) } }) } }) } }, fail: function(res) { // 获取权限信息失败,提示用户并退出应用程序 uni.showModal({ title: '提示', content: '无法获取网络访问权限信息,无法使用本应用程序', showCancel: false, complete() { uni.navigateBack({ delta: 1 }) } }) } }) ``` 2. 如果用户未授权,则请求网络访问权限。您可以使用uni.authorize()方法来请求网络访问权限。如果用户授权成功,则加载应用程序;否则,提示用户并退出应用程序。 3. 如果用户拒绝授权,则提示用户并退出应用程序。您可以使用uni.showModal()方法来显示提示框,提示用户网络访问权限是应用程序的必要权限,如果用户拒绝授权,则无法使用应用程序。 需要注意的是,如果用户在第一次启动应用程序时拒绝了网络访问权限,下次启动应用程序时仍然需要重新请求网络访问权限。因此,您需要在应用程序的启动逻辑中处理好这些情况,以确保应用程序的正常运行。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值