2015-07-30 16 views
15

Bir bölgedeki tüm WiFi ağlarını ve SSID değerini almak istiyorum. Ancak sorun, bir ağa bağlı olmasam bile tüm WiFi ağının SSID'sini nasıl alacağınızdır.iOS'ta kullanılabilir wifi ağ adı nasıl kullanılabilir

import UIKit 
import Foundation 
import SystemConfiguration.CaptiveNetwork 

class FirstView: UIViewController 
{ 
    @IBOutlet weak var label: UILabel! 

    override func viewDidLoad() 
    { 
     super.viewDidLoad() 
     let ssid = self.getWiFiName() 
     print("SSID: \(ssid)") 
    } 

    func getWiFiName() -> String? { 
     var ssid: String? 
     if let interfaces = CNCopySupportedInterfaces() as NSArray? { 
      for interface in interfaces { 
       if let interfaceInfo = CNCopyCurrentNetworkInfo(interface as! CFString) as NSDictionary? { 
        ssid = interfaceInfo[kCNNetworkInfoKeySSID as String] as? String 
        break 
       } 
      } 
     } 
     return ssid 
    } 
} 
+0

i mevcut tüm WiFi listesini almak olamaz. –

+0

Kolayca değil. Wifi ağlarını taramak bir güvenlik tehdididir. – Sulthan

+3

Ben hızlı bir google arama ile SO üzerinde sorulan benzer sorular buldum, ortak bir cevap, sizin için de geçerli olabilirken, elinizde – RubberDucky4444

cevap

1

sınıfım;

ithalat SystemConfiguration.CaptiveNetwork Sonra

; i aynı sorun var @EnricoSusatyo

func getInterfaces() -> Bool { 
    guard let unwrappedCFArrayInterfaces = CNCopySupportedInterfaces() else { 
     print("this must be a simulator, no interfaces found") 
     return false 
    } 
    guard let swiftInterfaces = (unwrappedCFArrayInterfaces as NSArray) as? [String] else { 
     print("System error: did not come back as array of Strings") 
     return false 
    } 
    for interface in swiftInterfaces { 
     print("Looking up SSID info for \(interface)") // en0 
     guard let unwrappedCFDictionaryForInterface = CNCopyCurrentNetworkInfo(interface) else { 
      print("System error: \(interface) has no information") 
      return false 
     } 
     guard let SSIDDict = (unwrappedCFDictionaryForInterface as NSDictionary) as? [String: AnyObject] else { 
      print("System error: interface information is not a string-keyed dictionary") 
      return false 
     } 
     for d in SSIDDict.keys { 
      print("\(d): \(SSIDDict[d]!)") 
     } 
    } 
    return true 
} 
+2

Bu sadece bağlı arayüz SSID'yi gösteriyor. – picciano

+0

'var ssid =" "; (CNCopySupportedInterfaces() olarak? [CFString]) ?. forEach ({ ssid = (CNCopyCurrentNetworkInfo ($ 0) as? [String: Any])? [KCNNetworkInfoKeySSID dizesi olarak? Dize ?? ""}) ' –

6

İlk WIFI ağ adını yazdıran

İşte
+1

Bu şu anda bağlı olan wifi'yi en azından iOS 11.2.2 üzerinde bir iPhone 7'ye döndürüyor gibi görünüyor – DCIndieDev

İlgili konular