How to decode a QR code that contains data for WIFI connection in AVFoundation

I use AVFoundation to read the QR Code, after reading I get a string, the pattern "WIFI:S:name-of-network;T:WPA;P:password;;" How do I decode, with the ability to connect, and output separately password, name in label.text I am new to swift, I would be grateful if you could describe the solution to the problem in detail. Thank you.

Answered by Claude31 in 736927022

If the pattern is a fix pattern, you can easily parse the string to extract information you need.

Please also show the complete and exact string you get. That will help confirm the following.

Typically, you would first split the inputString in components

            let components : [String] = inputString.components(separatedBy: ";")

That will give you an array of Strings with:

components[0] : "WIFI:S:name-of-network"
components[1] : "T:WPA"
components[2] : "P:password"
// etc

From there, you can easily extract name-of-network, password… doing the same with ":" separator.

Hope that helps.

Accepted Answer

If the pattern is a fix pattern, you can easily parse the string to extract information you need.

Please also show the complete and exact string you get. That will help confirm the following.

Typically, you would first split the inputString in components

            let components : [String] = inputString.components(separatedBy: ";")

That will give you an array of Strings with:

components[0] : "WIFI:S:name-of-network"
components[1] : "T:WPA"
components[2] : "P:password"
// etc

From there, you can easily extract name-of-network, password… doing the same with ":" separator.

Hope that helps.

How to decode a QR code that contains data for WIFI connection in AVFoundation
 
 
Q