简体   繁体   English

使用IONIC的IOS上没有网络连接功能问题

[英]No network connection functionality issue on IOS using IONIC

I am working on my No Connection functionality (my app must be connected to work). 我正在使用我的“无连接”功能(我的应用必须已连接才能正常工作)。 I detect the Network Connection and redirect to a page with a retry button and nice message. 我检测到网络连接,并使用重试按钮和好消息重定向到页面。 This works great on Android but not on iOS9 这在Android上效果很好,但在iOS9上效果不佳

if (window.Connection) {
     $rootScope.currentState = $state.current.name;
     if (navigator.connection.type == Connection.NONE) {
         $state.go('internet-error');
     } else{
         $state.go('login');
     }
 }

Try to give some solution is that any changes require on config.xml 尝试给出一些解决方案是对config.xml进行任何更改

First you need to install cordova-plugin-network-information plugin 首先,您需要安装cordova-plugin-network-information 插件

https://github.com/apache/cordova-plugin-network-information https://github.com/apache/cordova-plugin-network-information

then add following code 然后添加以下代码

.run(function($rootScope, $location, $state, $ionicPlatform) {
    $ionicPlatform.ready(function() {        
        $rootScope.$on("$locationChangeStart", function(event, next, current)    {      
            if (window.Connection) {
                if (navigator.connection.type == Connection.NONE) {
                    $state.go('internet-error');
                }else{
                    $state.go('login');
                }
             }
        }); 
    });     
})

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM