I'm building an app that uses a QR Code to connect users, similar to how Snapchat allows users to add each other on Snapchat.
I was hoping to use a more aesthetically pleasing alternative to the QR Code, something similar to Snapchat's Snapcode. Any idea as to how it can be done in an iOS application?
You can publicize your Snapcode on the web, social media, and print.
A Snapcode is a unique code you can scan to access features or unique content on Snapchat. Each Lens created in Lens Studio generates its own Snapcode that can be unlocked by people everywhere.
To use the feature, open “Settings” and select “Snapcodes,” then “Create Snapcode.” Enter the URL, add an image from the website or your phone, resize it so it fits inside the Snapchat ghost logo and then you can save it for use wherever.
If you don't want to use QRCode at all you'll have to create your own pattern to generate/reading the image.
But maybe you can use QRCode.
QRCode has an error correction level. Considering it you can still make your QRCode more aesthetically pleasing as you asked for. Just keep in mind "The higher the error correction level, the less storage capacity" and you can customize your image as long as the algorithm can get the info you need.
When you're generating the QRCode image you can do it like this:
Swift 3.1
private enum InputCorrectionLevel: String {
case low = "L" // 7%
case medium = "M" // 15%
case high = "Q" // 25%
case ultra = "H" // 30%
}
private enum QRCodeGenerationError {
case initializingFilter
case applyingFilter
}
func qrCode(from string: String, withSize frameSize: CGSize) throws -> CIImage {
guard let filter = CIFilter(name: "CIQRCodeGenerator") else {
throw QRCodeGenerationError.initializingFilter
}
let data = string.data(using: .isoLatin1, allowLossyConversion: false)
filter.setValue(data, forKey: "inputMessage")
filter.setValue(InputCorrectionLevel.low.rawValue, forKey: "inputCorrectionLevel")
guard let outputImage = filter.outputImage else {
throw QRCodeGenerationError.applyingFilter
}
let scaleX = frameSize.width / outputImage.extent.size.width
let scaleY = frameSize.height / outputImage.extent.size.height
let qrCodeCIImage = outputImage.applying(CGAffineTransform(scaleX: scaleX, y: scaleY))
return qrCodeCIImage
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With