Apple Mandatory - Test Celular Connection - Solved


#1

Hello Everyone, today I’m not come to ask but share.

Like a Apple developer, I get some work here about the connection test that is mandatory for publish an app to the apple store (iTunnes Store) and I spend like a three days trying to find the solution… After I find, I decide to share here because I can’t find on this forum that helps me a lot, so here we go…

This tip, is for you that like me, have problems with Cordova Network Plugin on iOS:

First, and after you already have the plugin installed on your project, before you open your project on Xcode you’ll need to add and build your project with cordova…

cordova platform add ios
cordova build

after that you’ll need edit config.xml and add the lines:

<feature name="NetworkStatus">
<param name="ios-package" value="CDVConnection" />
</feature>

and on your Index.html…

<script type="text/javascript">
    document.addEventListener("deviceready", onDeviceReady, false);
    // device APIs are available
    function onDeviceReady() {
        if(navigator.network.connection.type == Connection.NONE){
            alert("No Connection");
        }else{
            alert("Connected");
        }
    }
</script>

And dont forget to insert on you app run (app.js)

if (window.StatusBar) {
  // org.apache.cordova.statusbar required
  StatusBar.styleDefault();
}

// just this follow lines
if(window.Connection){
if(navigator.connection.type == Connection.NONE){
alert(“Your message for no connection!”);
}
}

This simple steps should solve all your problems with network connections on Xcode Simulator and on your iOS device.

Hope this helps.