我正在尝试使用多个字符串生成QRCode。它正在工作,但生成的图像QRCode在imageView
内部太小,因此无法读取它(至少我认为这就是为什么我无法从中获取信息)。
它的外观如下:
就像这样我生成它:
func generateQRWithInfo(){
var aggregateData = [String: NSData]()
if let firstName = firstName?.data(using: String.Encoding.isoLatin1, allowLossyConversion: false) {
aggregateData.updateValue(firstName as NSData, forKey: "firstName")
}
if let lastName = lastName?.data(using: String.Encoding.isoLatin1, allowLossyConversion: false) {
aggregateData.updateValue(lastName as NSData, forKey: "lastName")
}
if let job = job?.data(using: String.Encoding.isoLatin1, allowLossyConversion: false) {
aggregateData.updateValue(job as NSData, forKey: "job")
}
if let organization = organization?.data(using: String.Encoding.isoLatin1, allowLossyConversion: false) {
aggregateData.updateValue(organization as NSData, forKey: "organization")
}
if let mobilePhone = mobilePhone?.data(using: String.Encoding.isoLatin1, allowLossyConversion: false) {
aggregateData.updateValue(mobilePhone as NSData, forKey: "mobilePhone")
}
if let workPhone = workPhone?.data(using: String.Encoding.isoLatin1, allowLossyConversion: false) {
aggregateData.updateValue(workPhone as NSData, forKey: "workPhone")
}
if let email = email?.data(using: String.Encoding.isoLatin1, allowLossyConversion: false) {
aggregateData.updateValue(email as NSData, forKey: "email")
}
let archived = NSKeyedArchiver.archivedData(withRootObject: aggregateData)
let filter = CIFilter(name: "CIQRCodeGenerator")
filter?.setValue(archived, forKey: "inputMessage")
filter?.setValue("Q", forKey: "inputCorrectionLevel")
let qrCodeImage = filter?.outputImage
let context = CIContext(options: nil)
//let cgImage = context.createCGImage(qrCodeImage!, from: (qrCodeImage?.extent)!)
let transform = CGAffineTransform(scaleX: 50,y: 50)
let output = filter?.outputImage?.applying(transform)
let newImage = UIImage(ciImage: output!)
qrImageView.image = newImage
}
我不知道它应该是怎么回事,但是我无法从中获取信息。我做错了什么?
答案 0 :(得分:1)
QR码根据这些参数保存大量数据。
数据类型可以是数字,字母数字和二进制。 基于可能的损耗恢复,可以将纠错级别分类为类型L,M,Q和H.
根据您的情况,您希望生成30 * 30个字母数字,因此显然您无法存储超过允许的值。所以要把它做大或减少数据。要记下所有QR码阅读器都不一样。
有关详细信息,请查看此table