IOS: swift gets the name of the Wi-Fi connection and the mac address of the ap.

Source: Internet
Author: User

IOS: swift gets the name of the Wi-Fi connection and the mac address of the ap.

After searching for the Internet for half a day, they all use various copy versions, not the swift version. After several experiments, we finally completed integration. I would like to share with you the following code in xcode7.1.

1. Because the system library needs to be imported in swift, a bridge Header. h is required and added to the bridge file.

 

# Import

 

2. Add the following functions in the swift file.

 

 

Func getMAC ()-> (success: Bool, ssid: String, mac: String) {if let cfa: NSArray = CNCopySupportedInterfaces () {for x in cfa {if let dict = CFBridgingRetain (CNCopyCurrentNetworkInfo (x! CFString) {let ssid = dict [SSID]! Let mac = dict [BSSID]! Return (true, ssid! String, mac! String) }}return (false ,,)}

3. Call

 

 

Let x = getMAC () if x. success {print (x. mac) print (x. ssid )}


 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.