Internet Connection?


How i do to ask if there if any internet connection in my device ?


I don’t think OpenFL provides this, so you’ll have to make an extension.

Follow the instructions in that post, but instead of, make a file named containing this:

#import "Network.h"

namespace network {
	bool isConnected() {
		return [[Reachability reachabilityForInternetConnection] currentReachabilityStatus]
			!= NotReachable;

Then add Network.h:

#ifndef NETWORK_H
#define NETWORK_H

#import "Reachability.h"

namespace network {
	bool isConnected();


And then use this for

package com.your.package;

import android.content.Context;

import org.haxe.extension.Extension;

public class Network {
	private static NetworkInfo getActiveNetworkInfo() {
		ConnectivityManager cm =
		return cm.getActiveNetworkInfo();
	public static boolean isConnected() {
		NetworkInfo activeNetwork = getActiveNetworkInfo();
		return activeNetwork != null && activeNetwork.isConnected();

For iOS, you’ll also need to include Apple’s Reachability class. Go here, click “Download Sample Code,” and then extract Reachability.h and Reachability.m.


Happy for pull requests, or to help extension code that we think should be in the core :slight_smile: