Join Wi-Fi Network from QR Code

I was wondering if anybody knows if it's possible for an app to use a QR code to join a Wi-Fi network - the same functionality as the iOS 11 Camera app?


I have some code reading a QR Code that looks something like - "WIFI:S:name-of-network;T:WPA;P:password;;"


This QR code works perfectly in the native camera app - asking the user if they'd like to join the Wi-Fi network and successfully joining if they do.


When I scan the QR code in my own code, I get the following error: canOpenURL: failed for URL: "WIFI:S:name-of-network;T:WPA;P:password;;" - error: "The operation couldn’t be completed. (OSStatus error -10814.)"

In my app, I've got URL Schemes for "prefs" and have added "wifi" in LSApplicationQueriesSchemes.

Am I doing something wrong, or is this simply not possible?

If it's not possible, is there anyway to use the iOS native camera functionality within an app?

Accepted Reply

In my app, I've got URL Schemes for "prefs" and have added "wifi" in

LSApplicationQueriesSchemes
.

This is not the right way forward here; these URL schemes are not documented for third-party use. See this post for more details on that issue.

When I scan the QR code in my own code, I get the following error: canOpenURL …

Is your app trying to open this URL? Or is that happening inside the framework you’re using to run the camera?

The way I’d expect this to work is as follows:

  1. You use the camera framework to get the text of the QR code.

  2. You parse that into its component parts (iOS has no API for this but the format seems to be pretty simple).

  3. You join the Wi-Fi network using

    NEHotspotConfigurationManager
    .

Share and Enjoy

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

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

Replies

This is one of those "Apple's apps have special privileges/get to cheat the system" moments.

In my app, I've got URL Schemes for "prefs" and have added "wifi" in

LSApplicationQueriesSchemes
.

This is not the right way forward here; these URL schemes are not documented for third-party use. See this post for more details on that issue.

When I scan the QR code in my own code, I get the following error: canOpenURL …

Is your app trying to open this URL? Or is that happening inside the framework you’re using to run the camera?

The way I’d expect this to work is as follows:

  1. You use the camera framework to get the text of the QR code.

  2. You parse that into its component parts (iOS has no API for this but the format seems to be pretty simple).

  3. You join the Wi-Fi network using

    NEHotspotConfigurationManager
    .

Share and Enjoy

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

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

Thanks Eskimo, this works perfectly!

Nice

Good

Oh, and seeing as this thread got reanimated, I should point out that there’s now some useful sample code in this space:

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Thanks