Giter Club home page Giter Club logo

ios13-wifi-info's Introduction

iOS13-WiFi-Info

Fix CNCopyCurrentNetworkInfo() does NOT work in iOS13 and later

Get Wi-Fi SSID in iOS 12 and earlier

stackoverflow

import Foundation
import SystemConfiguration.CaptiveNetwork

func getSSID() -> 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
}

To use CNCopyCurrentNetworkInfo() in iOS 12 and later, enable the Access WiFi Information capability in Xcode. For more information, see Access WiFi Information Entitlement.

CNCopyCurrentNetworkInfo() returns nil in iOS 13 and later

Watch WWDC19 Session 713: Advances in Networking, Part 2.

Now you all know the important privacy to Apple. And one of the things we realized. Is that... Accessing Wi-Fi information can be used to infer location.

So starting now, to access that Wi-Fi information. You'll need the same kind of privileges that you'll need to get other location information.

WWDC19-CNCopyCurrentNetworkInfo().png

Requires Capability: Access Wi-Fi Information

Must also meet at least one of criteria below

  • Apps with permission to access location
  • Currently enabled VPN app
  • NEHotspotConfiguration (only Wi-Fi networks that the app configured)

Otherwise, returns nil

Get Wi-Fi SSID in iOS 13 and later

Import Core Location framework

import CoreLocation

Function to update UI

func updateWiFi() {
    print("SSID: \(currentNetworkInfos?.first?.ssid)")
    ssidLabel.text = getSSID()
}

Ask location permission

if #available(iOS 13.0, *) {
    let status = CLLocationManager.authorizationStatus()
    if status == .authorizedWhenInUse {
        updateWiFi()
    } else {
        locationManager.delegate = self
        locationManager.requestWhenInUseAuthorization()
    }
} else {
    updateWiFi()
}

Implement CLLocationManagerDelegate

class ViewController: UIViewController, CLLocationManagerDelegate {
    ...
    func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus) {
        if status == .authorizedWhenInUse {
            updateWiFi()
        }
    }
    ...
}

Update your app

If your app uses CNCopyCurrentNetworkInfo() and needs to solve the issue. Solve it now. There's no need to wait for Xcode 11 GM. The solution above is Xcode 10 compatible.

ios13-wifi-info's People

Contributors

hackinggate avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ios13-wifi-info's Issues

iOS 13 adaptation

Need to adapt the App on the AppStore? or Apple will do it yourself?

Return value for CLLocationManager.authorizationStatus()

I need to detect network changes in background.
But there was a problem when requesting location permission.

CLLocationManager.authorizationStatus() returns .authorisedAlways when the device is set to “While Using the App”

Maybe because I don't know iOS and Swift well. What's wrong?

override func viewDidLoad() {
    super.viewDidLoad()

    if #available(iOS 13.0, *) {
        let status = CLLocationManager.authorizationStatus()
            
        if status == .authorizedAlways {
            print("Always")
            startWifiDetection()
        } else if status == .authorizedWhenInUse {
            print("While Using the App")
            locationManager.delegate = self
            locationManager.requestAlwaysAuthorization()
        } else {
            print("Never or Ask Next Time")
            locationManager.delegate = self
            locationManager.requestWhenInUseAuthorization()
        }
    }
}

Got reject when using CoreLocation to get wifi ssid on ios13

I got reject from apple when using CoreLocation to get wifi SSID, because of my app only use this to detecting current wifi and this is not enough to pass apple review

Guideline 2.5.4 - Performance - Software Requirements

Your app declares support for location in the UIBackgroundModes key in your Info.plist file but does not have any features that require persistent location. Apps that declare support for location in the UIBackgroundModes key in your Info.plist file must have features that require persistent location.

Anybody know another way to get current wifi SSID? thank.

information return in beta6.

In beta6, I can get below information:
{
BSSID = "00:00:00:00:00:00";
SSID = WLAN;
SSIDDATA = <574c414e>;
}

no nil return now. :)

NEHotspotConfiguration option

My app's functionality does not require location permission, so Apple rejects the app if I requires location permission. But my app does use NEHotspotConfiguration which is listed as the last bullet in WWDC slide.

Do you know how I can make that work?

iOS 13 Beta 2 stopped working!!

First of all thank you for you solution. This worked initially, but since updating to ios13 beta2 it no longer works. CNCopySupportedInterfaces is returning nil. My app has location permission while using the app. Any thoughts?

Validate Password

Hi am able to get the SSID But in my requirement I have to validate password also. So user will enter the password in app and I have to validate that password is correct or not.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.