蔡cai
蔡cai
  • 发布:2025-09-03 11:54
  • 更新:2025-09-03 11:54
  • 阅读:23

【解决ios网络问题】处理ios app端网络问题

分类:uni-app

在utils目录下添加network.js文件

// 监听网络变化  
export const watchNetwork = () => {  
    // #ifdef APP  
    uni.onNetworkStatusChange((res) => {  
        if (res.networkType && res.networkType !== "none") {  
            uni.showModal({  
                title: "温馨提示",  
                content: "已连接网络,请重新加载应用",  
                showCancel: false,  
                success: (res) => {  
                    if (res.confirm) {  
                        plus.runtime.restart();  
                    }  
                }  
            })  
        }  
    })  
    // #endif  
}  

// 获取当前网络状态  
export const getNetworkType = () => {  
    // #ifdef APP  
    uni.getNetworkType({  
        success: (res) => {  
            if (res.networkType && res.networkType === "none") {  
                uni.showToast({  
                    title: "当前未开启网络,请前往设置开启",  
                    icon: "none"  
                })  
                watchNetwork();  
            }  
        }  
    })  
    // #endif  
}

App.vue添加以下代码

import { getNetworkType } from "@/utils/network.js";  
export default {  
    onLaunch: function() {  
        getNetworkType();  
    }  
}
0 关注 分享

要回复文章请先登录注册