iOS Question Get more Wifi information?

Discussion in 'iOS Questions' started by davemorris, Feb 14, 2019 at 1:45 PM.

  1. davemorris

    davemorris 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?
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    1.

    Whether wifi is enabled:

    Code:
    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
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice