この記事は公開されてから1年以上経過しています。情報が古い可能性がありますので、ご注意ください。
接続されているネットワークのSSIDを参照する方法です。 ちょっと調べる機会があったので、自分メモ代わりに記載します。
iOS8
iOS7、iOS8の場合は下記で取得出来る様です。
@import SystemConfiguration.CaptiveNetwork;
/** Returns first non-empty SSID network info dictionary.
* @see CNCopyCurrentNetworkInfo */
- (NSDictionary *)fetchSSIDInfo
{
NSArray *interfaceNames = CFBridgingRelease(CNCopySupportedInterfaces());
NSLog(@"%s: Supported interfaces: %@", __func__, interfaceNames);
NSDictionary *SSIDInfo;
for (NSString *interfaceName in interfaceNames) {
SSIDInfo = CFBridgingRelease(
CNCopyCurrentNetworkInfo((__bridge CFStringRef)interfaceName));
NSLog(@"%s: %@ => %@", __func__, interfaceName, SSIDInfo);
BOOL isNotEmpty = (SSIDInfo.count > 0);
if (isNotEmpty) {
break;
}
}
return SSIDInfo;
}
iOS9
iOS9で試そうとした所、CaptiveNetworkが軒並みDeprecatedに。。。
検索したところ、NEHotspotHelperで取得出来るようですが、
#import <NetworkExtension/NetworkExtension.h>
NSArray * networkInterfaces = [NEHotspotHelper supportedNetworkInterfaces];
NSLog(@"Networks %@",networkInterfaces);
引用元:CaptiveNetwork Depreciated in iOS9
NEHotspotHelperクラスリファレンスには下記記載が、
IMPORTANT The com.apple.developer.networking.HotspotHelper entitlement is required in order to use NEHotspotHelper. To request this entitlement, send an email to networkextension@apple.com.
NEHotspotHelper Class Reference
意訳: このクラスを使いたかったら、networkextension@apple.comにメールを送って許可を受けてね。
という訳で、iOS9以降でSSID情報を取得したい場合は、Appleに申請が必要みたいです。