iOS Question Get more Wifi information?

Status
Not open for further replies.

davemorris

Active Member
Licensed User
Hi all,
In B4A, it's possible to use the Simple Wifi library here – https://www.b4x.com/android/forum/threads/simple-wifi-library-updated-v-3-07-09-05-2018.76233/ (which is based on the MLwifi library) to get all kinds of information about the Wifi connection, which I can't find in B4i.

I've seen that it's possible in B4i to find out if the Wifi is connected to a network by calling ServerSocket.GetMyWifiIp, as it returns "127.0.0.1" if not connected, but there are a number of other things that I've done in B4A that I can't find out how to do in B4i (or if they are possible), specifically:
- Detect if the phone's Wifi is switched on (not whether it is connected to a network)
- Get the signal strength, either in decibels or as a percentage
- Ping an IP address to see if it is online

Any ideas?
 

Erel

Administrator
Staff member
Licensed User
1.

Whether wifi is enabled:

B4X:
Dim no As NativeObject = Me
Dim WiFiEnabled As Boolean = no.RunMethod("isWiFiEnabled", Null).AsBoolean

End Sub

#if OBJC
#import <ifaddrs.h>
#import <net/if.h>
- (BOOL) isWiFiEnabled {

    NSCountedSet * cset = [NSCountedSet new];

    struct ifaddrs *interfaces;

    if( ! getifaddrs(&interfaces) ) {
        for( struct ifaddrs *interface = interfaces; interface; interface = interface->ifa_next) {
            if ( (interface->ifa_flags & IFF_UP) == IFF_UP ) {
                [cset addObject:[NSString stringWithUTF8String:interface->ifa_name]];
            }
        }
    }

    return [cset countForObject:@"awdl0"] > 1 ? YES : NO;
}
#End If
2. Signal strength is not available.

3. Pinging is actually not possible on Android (without using a shell command). It might be possible to make a real ping with a library or inline low level code. If anyone likes to build such a library: https://developer.apple.com/library...00716-Common_SimplePing_m-DontLinkElementID_4
 

ilan

Expert
Licensed User
1.

Whether wifi is enabled:

B4X:
Dim no As NativeObject = Me
Dim WiFiEnabled As Boolean = no.RunMethod("isWiFiEnabled", Null).AsBoolean

End Sub

#if OBJC
#import <ifaddrs.h>
#import <net/if.h>
- (BOOL) isWiFiEnabled {

    NSCountedSet * cset = [NSCountedSet new];

    struct ifaddrs *interfaces;

    if( ! getifaddrs(&interfaces) ) {
        for( struct ifaddrs *interface = interfaces; interface; interface = interface->ifa_next) {
            if ( (interface->ifa_flags & IFF_UP) == IFF_UP ) {
                [cset addObject:[NSString stringWithUTF8String:interface->ifa_name]];
            }
        }
    }

    return [cset countForObject:@"awdl0"] > 1 ? YES : NO;
}
#End If
2. Signal strength is not available.

3. Pinging is actually not possible on Android (without using a shell command). It might be possible to make a real ping with a library or inline low level code. If anyone likes to build such a library: https://developer.apple.com/library...00716-Common_SimplePing_m-DontLinkElementID_4
on my iphone 11 it returns always true. even if wifi is off and also if cellular connection is off it still rturn true. even in airplane mode.
 

ilan

Expert
Licensed User
Note that when you "turn off" wifi from the control panel it only disconnects the currently connected network.
hm.. ok i did not knew that. if i turn it off in settings it returns false as expected.

Turn on airplane mode
i tried airplane mode but still returns true. airplane mode does not turn off wifi. the only way to get FALSE is by going to settings and turn it there off.

so i guess there is no option to know if the phone is connected to wifi? because this is what is important for my app.

thanx
 
Status
Not open for further replies.
Top