是否可以运行一种方法来返回用户连接到的无线网络的名称?在我的应用程序内部,我希望能够返回用户连接到的无线网络的名称。
最佳答案
这对我来说很完美:
#import <SystemConfiguration/CaptiveNetwork.h>
CFArrayRef myArray = CNCopySupportedInterfaces();
CFDictionaryRef myDict = CNCopyCurrentNetworkInfo(CFArrayGetValueAtIndex(myArray, 0));
// NSLog(@"SSID: %@",CFDictionaryGetValue(myDict, kCNNetworkInfoKeySSID));
NSString *networkName = CFDictionaryGetValue(myDict, kCNNetworkInfoKeySSID);
if ([networkName isEqualToString:@"Hot Dog"])
{
self.storeNameController = [[StoreDataController alloc] init];
[self.storeNameController addStoreNamesObject];
}
else {
UIAlertView *alert = [[UIAlertView alloc]initWithTitle: @"Connection Failed"
message: @"Please connect to the Hot Dog network and try again"
delegate: self
cancelButtonTitle: @"Close"
otherButtonTitles: nil];
[alert show];