Enable hotspot using Swift

Hi,

I am lookig for a way to activate Hotspot from my app without existing to the netowrk settings screen.


My goal is to have a minimum user interaction (defining hotspot name, hotspot password, ect..). All I want from the usre is permission to activate a hotspot (will be done by somekind of dialog).

I looked into `

NEHotspotConfiguration` and `NEHotspotConfigurationManager` to confiure a hotspot and connect as follow:

```

1. let hotspotConfig = NEHotspotConfiguration(ssid:***, passphrase:***, isWEP: false)

2. hotspotConfig.joinOnce = false

3. NEHotspotConfigurationManager.shared.apply(hotspotConfig)

```

This enable me to configure a personal wifi AC but I can't "see" it from other devices.


My goal is to activate hotspot so other devices can connect to it.


I understood that I need special approval from apple to use NetworkExtension framework and I sent a request over 2 weeks but I still did not recieve any reply besides a request number.

Replies

I’d like to confirm your requirements here. Do you want to:

  • Enable Personal Hotspot on the iOS device, so that it publishes a network that other Wi-Fi clients can connect to?

  • Force the iOS device to join a specific Wi-Fi network that’s being published by some other hardware?

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Hi eskimo,


I would like to `Enable Personal Hotspot on the iOS device, so that it publishes a network that other Wi-Fi clients can connect to?`.


Of course, this will be done only if the user will approve (via a dialog). I want to make the app accessible to users that are not tech-savvy.


By the way, I am also still wafting for a reply for my request (#708716875) to use the network extension framework that I understood I need for this purpose.
(I used this answer as reference - https://stackoverflow.com/questions/46767138/nehotspothelper-register-not-received-call-back-ios11/52472782#52472782)

I would like to Enable Personal Hotspot on the iOS device, so that it publishes a network that other Wi-Fi clients can connect to?.

iOS has no API for configuring Personal Hotspot.

If you’d like to see such an API added in the future, I encourage you to file an enhancement request describing your requirements. Please post your bug number, just for the record.

NEHotspotHelper
, the API whose entitlement you applied for, lets your create an app that helps the user navigate a hotspot (a Wi-Fi network where the user must interact with the network to gain access to the wider Internet). It’s completely orthogonal to Personal Hotspot.

For a summary of all the Wi-Fi APIs available on iOS, read QA1942 iOS Wi-Fi Management APIs.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

So, If I understood correctly, currently there no way to create hotspot (personal hotspot as you called it) so it publishes a network that other WiFi clients can connect to.


From your experience, how much time this kind of enhancement will be added if I my enhancement request will be accepted?


I would also like to elaborate the original question.

If I want to share with the connected device/accessory (the device/accessory is connected via BLE and currently is not part of the MFi program) the WiFi SSID and credentials that the iOS (which run my app) is currently connected to, how can I do it?

I tried using 'HomeKit', using `HMHomeManagerDelegate` and 'HMAccessoryBrowser` API but I need found my device/accessory.

currently there no way to create hotspot (personal hotspot as you called it) so it publishes a network that other WiFi clients can connect to.

Correct.

From your experience, how much time this kind of enhancement will be added if I my enhancement request will be accepted?

I’m sorry, I can’t predict the future.

If I want to share with the connected device/accessory … the WiFi SSID and credentials that the iOS (which run my app) is currently connected to, how can I do it?

There’s no way to do this programmatically. You can get the iOS device’s current Wi-Fi network SSID using

CNCopyCurrentNetworkInfo
, but there’s no way to get the corresponding credentials.

The only good way to solve this problem is to have your accessory support Wireless Accessory Configuration (WAC). See QA1942 for more on that. All the other solutions require one compromise or another.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

I read about Wireless Accessory Configuation (WAC) here - https://developer.apple.com/library/archive/qa/qa1942/_index.html


And it says that "Important: The on-the-wire protocols used by this peer-to-peer networking are not documented for third-party use, so this technique only works between Apple devices."


my device/accessory is not an apple device. Is there another way?

WAC and peer-to-peer Wi-Fi are different things. Which one are you asking about?

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Sorry, my mistake.

Peer-to-peer is not relevant for me because the accessory/device is not an apple device.


I could not find an example to WAC. can you direct me to something concrete?
I also find this Q&A in the forum: https://forums.developer.apple.com/thread/86783

Is that answer correct and still relevant? Am I required to enrol to MFi program?

I could not find an example to WAC. can you direct me to something concrete?

There’s lots of concrete info about WAC in the WWDC presentations linked to by QA1942. If you’re looking for more technical details, you won’t find them. WAC is part of MFi and thus the technical information is not available publicly.

Am I required to enrol to MFi program?

Yes. QA1924 is perfectly clear about this:

WAC … accessories must be built under the aegis of the MFi program.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Hi,


Lets say that I asked the user to manual open a personal hotspot, how can I identify the personal hotspot status.

I tried this direction:


    @objc 
    func getCurrentNetwork(_ resolve: RCTPromiseResolveBlock, rejecter reject: RCTPromiseRejectBlock) 
    { 
        var networkDict = [String : Any]() 
        let deviceName = UIDevice.current.name 
        print("device name: \(deviceName)") 
        guard let interfaces = CNCopySupportedInterfaces() as? [String] else { 
            reject("ios_errors", "Can't work on simulators", nil) 
            return 
        } 
        for interface in interfaces { 
            print("Looking up SSID info for \(interface)") 
            guard let interfaceInfo = CNCopyCurrentNetworkInfo(interface as CFString) else { 
                print("System error: \(interface) has no information") 
                return 
            } 
            guard let networkInfo = (interfaceInfo as NSDictionary) as? [String: AnyObject] else { 
                print("System error: interface information is not a string-keyed dictionary") 
                return 
            } 
            for key in networkInfo.keys { 
                networkDict["\(key)"] = "\(networkInfo[key]!)" 
            } 
        } 
        resolve(networkDict) 
    }

This code return the SSID name (and other information) to the client when the iPhone is connected to public hotspot, but when I activate the personal hotspot of the mobile device I enter line 17:

print("System error: \(interface) has no information")


And exit without getting the name of the hotspot, any ideas?


Is there a flag of something that indicate that the personal hotspot is enabled/disabled in `NEHotspotHelper` interface or `NEHotspotConguration` class?


Thanks

how can I identify the personal hotspot statu

There’s also no API for interrogating the status of Personal Hotspot.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Is there a way to identify, programmatically, that the personal hotspot is enabled and display the SSID (device name) of the personal hotspot?

Is getting the WI-FI IP address and check if it starts with `172.20.10` is a valid way to validate that the hotspot is active?

Is there a way to identify, programmatically, that the personal hotspot is enabled and display the SSID (device name) of the personal hotspot?

No. In my previous response I wrote

There’s also no API for interrogating the status of Personal Hotspot.

and things haven’t changed since yesterday (-:

Is getting the WI-FI IP address and check if it starts with 172.20.10 is a valid way to validate that the hotspot is active?

No. 172.16/12 is a standard range of private IP addresses and could be used by any network infrastructure. For example, my Mac regularly has 172.16/12 addresses because it’s used by VMware Fusion’s network bridging.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"
No.  In my previous response I wrote
There’s also no API for interrogating the status of Personal Hotspot.

and things haven’t changed since yesterday (-:

My intention was, is there a workaround to identify personal hotspot state programmatically since there is not API for that, that is why I continued the question regarding the ip address that starts with "172.10.20".
Do you have a suggestion on how this ability can be achieved (Identify personal hotspot active or not) ?
Another direction, I seen a lot abot Reachability library that can monitor the network reachabilty

Reachability : https://developer.apple.com/library/archive/samplecode/Reachability/Introduction/Intro.html

how to use example: https://medium.com/@sauvik_dolui/network-status-monitoring-on-ios-part-1-9a22276933dc


few questions about it:

1. Is it something apple still support it and an app won't be rejected if using it?

2. If I detect cellular connection, using the Reachablity, can I conclude that personal hotspot is active?

is there a workaround to identify personal hotspot state programmatically since there is not API for that

No. If there was a workaround I was comfortable with, I’d have explained it earlier. In this case your proposed workarounds all rely on the implementation details of Personal Hotspot, and such implementation details might change over time.

Personal Hotspot is a user-level feature, and it’s a mistake to attempt to use it as a developer-level feature. For example, you could imagine a future device that implements Personal Hotspot entirely within the baseband processor, with absolutely no visibility to the application processor on which your code runs. That would fulfil Personal Hotspot’s user-level goal — devices connected to the Wi-Fi published by the baseband processor would be able to access the Internet over WWAN — but it would break any app that depends on the current implementation.

Another direction, I seen a lot abot Reachability library that can monitor the network reachabilty

1. Is it something apple still support it and an app won't be rejected if using it?

SCNetworkReachability
is still a supported API, although one with many caveats.

2. If I detect cellular connection, using the Reachablity, can I conclude that personal hotspot is active?

No.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"