Ako v systéme iOS vedieť, s ktorým hostiteľom siete je zariadenie pripojené. Chcem sa v Swifte naučiť, ako môžeme skontrolovať, na ktorej konkrétnej sieti sme pripojení.
odpovede:
1 pre odpoveď č. 1Pomocou tejto vlastnej triedy sa dostanete do siete Wi-Fi, ku ktorej ste momentálne pripojení: -
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
}
}
Informácie môžete získať týmto spôsobom: -
print(SSID.fetchSSIDInfo())