diff --git a/packages/network_info_plus/network_info_plus/example/ios/Runner/AppDelegate.swift b/packages/network_info_plus/network_info_plus/example/ios/Runner/AppDelegate.swift index 70693e4a8c..b636303481 100644 --- a/packages/network_info_plus/network_info_plus/example/ios/Runner/AppDelegate.swift +++ b/packages/network_info_plus/network_info_plus/example/ios/Runner/AppDelegate.swift @@ -1,7 +1,7 @@ import UIKit import Flutter -@UIApplicationMain +@main @objc class AppDelegate: FlutterAppDelegate { override func application( _ application: UIApplication, diff --git a/packages/network_info_plus/network_info_plus/ios/network_info_plus/Sources/network_info_plus/FPPNetworkInfoPlusPlugin.m b/packages/network_info_plus/network_info_plus/ios/network_info_plus/Sources/network_info_plus/FPPNetworkInfoPlusPlugin.m index 50c05e2693..64161b9280 100644 --- a/packages/network_info_plus/network_info_plus/ios/network_info_plus/Sources/network_info_plus/FPPNetworkInfoPlusPlugin.m +++ b/packages/network_info_plus/network_info_plus/ios/network_info_plus/Sources/network_info_plus/FPPNetworkInfoPlusPlugin.m @@ -69,6 +69,7 @@ - (NSString *)getWifiIP { __block NSString *addr = nil; [self enumerateWifiAddresses:AF_INET usingBlock:^(struct ifaddrs *ifaddr) { + if (addr) return; addr = [self descriptionForAddress:ifaddr->ifa_addr]; }]; return addr; @@ -78,6 +79,7 @@ - (NSString *)getWifiIPv6 { __block NSString *addr = nil; [self enumerateWifiAddresses:AF_INET6 usingBlock:^(struct ifaddrs *ifaddr) { + if (addr) return; addr = [self descriptionForAddress:ifaddr->ifa_addr]; }]; return addr; @@ -87,6 +89,7 @@ - (NSString *)getWifiSubmask { __block NSString *addr = nil; [self enumerateWifiAddresses:AF_INET usingBlock:^(struct ifaddrs *ifaddr) { + if (addr) return; addr = [self descriptionForAddress:ifaddr->ifa_netmask]; }]; return addr; @@ -96,6 +99,7 @@ - (NSString *)getWifiBroadcast { __block NSString *addr = nil; [self enumerateWifiAddresses:AF_INET usingBlock:^(struct ifaddrs *ifaddr) { + if (addr) return; addr = [self descriptionForAddress:ifaddr->ifa_dstaddr]; }]; return addr; @@ -138,20 +142,22 @@ - (void)enumerateWifiAddresses:(NSInteger)family // retrieve the current interfaces - returns 0 on success success = getifaddrs(&interfaces); - if (success == 0) { - // Loop through linked list of interfaces - temp_addr = interfaces; - while (temp_addr != NULL) { + if (success != 0) { + NSLog(@"Error: getifaddrs() failed with error code: %d", success); + return; + } + + // Loop through linked list of interfaces + temp_addr = interfaces; + while (temp_addr != NULL) { if (temp_addr->ifa_addr->sa_family == family) { - // en0 is the wifi connection on iOS - if ([[NSString stringWithUTF8String:temp_addr->ifa_name] - isEqualToString:@"en0"]) { - block(temp_addr); - } + // One of `en` interfaces should be WiFi interface + if (strncmp(temp_addr->ifa_name, "en", 2) == 0) { + block(temp_addr); + } } temp_addr = temp_addr->ifa_next; - } } // Free memory