/ / Come sapere in IOS che con quale rete host il dispositivo è connesso - ios, iphone, swift, cacao-touch, swift3

Come sapere in ios che con quale rete host il dispositivo è connesso - ios, iphone, swift, cacao-touch, swift3

Come sapere in IOS con quale host di rete è connesso il dispositivo. Voglio imparare in Swift che, come possiamo verificare a quale particolare rete siamo connessi.

risposte:

1 per risposta № 1

Usa questa classe personalizzata per raggiungere la rete wifi sulla quale sei attualmente connesso: -

import Foundation
import SystemConfiguration.CaptiveNetwork

public class SSID {

class func fetchSSIDInfo() -> String {

var currentSSID = ""
if let interfaces = CNCopySupportedInterfaces() {
for i in 0..<CFArrayGetCount(interfaces) {
let interfaceName: UnsafeRawPointer = CFArrayGetValueAtIndex(interfaces, i)
let rec = unsafeBitCast(interfaceName, to: AnyObject.self)
let unsafeInterfaceData = CNCopyCurrentNetworkInfo("(rec)" as CFString)
if unsafeInterfaceData != nil {
let interfaceData = unsafeInterfaceData! as NSDictionary!
print(interfaceData)
currentSSID = interfaceData?.value(forKey:"SSID") as! String
}
}
}
return currentSSID
}
}

Puoi ottenere le informazioni in questo modo: -

print(SSID.fetchSSIDInfo())