如何在iOS编程中检查网络提供商名称?

我需要检查设备是否已正确连接到“My-Wifi”网络。 如果已连接,那么我将向服务器发送一些数据,否则不会。

现在我只是使用Reachability类检查Internet连接。

那怎么检查呢?

您可以使用CNCopySupportedInterfaces()调用。

CFArrayRef interfaces = CNCopySupportedInterfaces(); CFIndex count = CFArrayGetCount(interfaces); for (int i = 0; i < count; i++) { CFStringRef interface = CFArrayGetValueAtIndex(interfaces, i); CFDictionaryRef netinfo = CNCopyCurrentNetworkInfo(interface); if (netinfo && CFDictionaryContainsKey(netinfo, kCNNetworkInfoKeySSID)) { NSString *ssid = (__bridge NSString *)CFDictionaryGetValue(netinfo, kCNNetworkInfoKeySSID); // Compare with your needed ssid here } if (netinfo) CFRelease(netinfo); } CFRelease(interfaces); 

根据我的经验,您通常会在数组中有一个接口,如果您已连接,它将是一个有效的结构,如果不是,则为NULL 。 我仍然让for循环存在以防万一。

只有在使用ARC时才需要使用__bridge