iOS Question currentWifiSSID method failing

Yanik Freeman

Member
Licensed User
Since the iOS 26.x.x release the currentWifiSSID method in the code below is failing with error "Object was not initialized (NSObject)..." when "no.RunMethod("currentWifiSSID", Null).AsString" is called, is anyone else experiencing this and/or have a possible solution? Location services are on for the app, I can confirm that this is still working on a device running an older iOS release.

B4X:
#Entitlement: <key>com.apple.developer.networking.wifi-info</key><true/>

.
.
.

Private Sub StartLocationUpdates

    Dim no As NativeObject = Me

    gstSSID = ""

    Try
        'if the user allowed us to use the location service or if we never asked the user before then we call LocationManager.Start.
        If LocManager.IsAuthorized Or LocManager.AuthorizationStatus = LocManager.AUTHORIZATION_NOT_DETERMINED Then
            LocManager.Start(0)
            gstSSID = no.RunMethod("currentWifiSSID", Null).AsString
            Log("Current SSID: " & gstSSID)
        End If
    Catch
    End Try
End Sub

#If OBJC
#import <SystemConfiguration/CaptiveNetwork.h>
- (NSString *)currentWifiSSID {
  NSString *ssid = nil;
  NSArray *ifs = (__bridge_transfer id)CNCopySupportedInterfaces();
  for (NSString *ifnam in ifs) {
  NSDictionary *info = (__bridge_transfer id)CNCopyCurrentNetworkInfo((__bridge CFStringRef)ifnam);
 // ssid = @"none";
  if (info[@"SSID"]) {
  ssid = info[@"SSID"];
  }
  }
  return ssid;
}
#end if
 
Last edited:

Yanik Freeman

Member
Licensed User
Update: CNCopyCurrentNetworkInfo is deprecated and will always return nil or an empty dictionary when an app is linked against the iOS 26 SDK (Xcode 26), even with the correct entitlements and permissions.

Attempted to migrate the code to use the modern NetworkExtension framework, specifically the NEHotspotNetwork.fetchCurrent() method as per below but the callback does not appear to be triggering. Not sure why this isn't working and which entitlements are required...

B4X:
#Entitlement: <key>com.apple.developer.networking.HotspotConfiguration</key><true/>
#Entitlement: <key>com.apple.developer.networking.wifi-info</key><true/>
#AdditionalLib: NetworkExtension.framework

.
.
.

Private Sub StartLocationUpdates
    Dim no As NativeObject = Me
    
    gstSSID = ""
    
    Try
        'if the user allowed us to use the location service or if we never asked the user before then we call LocationManager.Start.
        If LocManager.IsAuthorized Or LocManager.AuthorizationStatus = LocManager.AUTHORIZATION_NOT_DETERMINED Then
            LocManager.Start(0)
            no.RunMethod("fetchWiFi:", Null)
            'gstSSID = no.RunMethod("currentWifiSSID", Null).AsString
            'Log("Current SSID: " & gstSSID)
        End If
    Catch
    End Try
End Sub

Sub WiFi_Available (Success As Boolean, SSID As String, BSSID As String)
    If Success Then
        gstSSID = SSID
        Log("Current SSID: " & gstSSID)
    End If
End Sub

#If OBJC
#import <NetworkExtension/NetworkExtension.h>

- (void)fetchWiFi:(NSObject*)tag {
    [NEHotspotNetwork fetchCurrentWithCompletionHandler:^(NEHotspotNetwork * _Nullable currentNetwork) {
        if (currentNetwork != nil) {
            // Signal strength is often 0 or unpopulated in this specific API
            [self.bi raiseEvent:nil event:@"wifi_available:" params:@[@YES, currentNetwork.SSID, currentNetwork.BSSID]];
        } else {
            [self.bi raiseEvent:nil event:@"wifi_available:" params:@[@NO, @"", @""]];
        }
    }];
}
#End If
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
1. Add NSLog(@"something here");
And see whether the code is reached or not.

2. Example based on NEHotspotNetwork https://www.b4x.com/android/forum/t...nehotspotconfigurationmanager.169946/#content
3. The problem in this case is with the event name. The number of colons should always match the number of parameters:
B4X:
[self.bi raiseEvent:nil event:@"wifi_available:::" params:@[@YES, currentNetwork.SSID, currentNetwork.BSSID]];
 
Upvote 0
Top