Skip to content
Snippets Groups Projects
Commit 5c55fc44 authored by Matyáš Latner's avatar Matyáš Latner
Browse files

Fixed network type resolution for iOS

parent f6d67326
No related merge requests found
......@@ -5,6 +5,8 @@ import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.backends.iosrobovm.IOSApplication;
import com.badlogic.gdx.backends.iosrobovm.IOSApplicationConfiguration;
import org.robovm.apple.coreservices.CFHost;
import org.robovm.apple.coreservices.CFHostInfoType;
import org.robovm.apple.foundation.NSException;
import org.robovm.objc.block.VoidBlock1;
import org.robovm.apple.foundation.NSAutoreleasePool;
......@@ -106,16 +108,13 @@ public class IOSLauncher extends IOSApplication.Delegate {
@Override
public ConnectionType getConnectionType() {
InetSocketAddress socketAddress = new InetSocketAddress(CONNECTION_CHECK_HOST, CONNECTION_CHECK_PORT);
// RoboVM tries to retrive IP address using network connection. If we don't have it InetSocketAddress.getAddress() returns null
// in that case SCNetworkReachability.create(socketAddress) throws IllegalArgumentException
if (socketAddress.getAddress() == null) {
return ConnectionType.Unknown;
}
SCNetworkReachabilityFlags flags = SCNetworkReachability.create(socketAddress).getFlags();
SCNetworkReachabilityFlags flags = new SCNetworkReachability(CONNECTION_CHECK_HOST).getFlags();
if(flags.compareTo(SCNetworkReachabilityFlags.IsWWAN) == 1) return ConnectionType.Mobile;
else return ConnectionType.Wifi;
if(flags.compareTo(SCNetworkReachabilityFlags.IsWWAN) == 1) {
return ConnectionType.Mobile;
} else {
return ConnectionType.Wifi;
}
}
}
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment