I have done code for reading QR code but it sometimes does not read certain types of QR code.
IOS and google chrome is able to read codes no matter how they are, how to get the same kind of functionality...
output.setMetadataObjectsDelegate(self, queue: DispatchQueue.main)
output.metadataObjectTypes = [
	 AVMetadataObject.ObjectType.qr,			
	 AVMetadataObject.ObjectType.dataMatrix
]
code that I used for reading QR code as follows
class ViewController: UIViewController, AVCaptureMetadataOutputObjectsDelegate {
var video = AVCaptureVideoPreviewLayer()
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
//create session
let session = AVCaptureSession()
//Define capture device
let captureDevice = AVCaptureDevice.default(for: AVMediaType.video)
do
{
let input = try AVCaptureDeviceInput(device: captureDevice!)
session.addInput(input)
}
catch
{
print("ERROR")
}
let output = AVCaptureMetadataOutput()
session.addOutput(output)
output.setMetadataObjectsDelegate(self, queue: DispatchQueue.main)
output.metadataObjectTypes = [AVMetadataObject.ObjectType.qr, AVMetadataObject.ObjectType.dataMatrix]
video = AVCaptureVideoPreviewLayer(session: session)
video.frame = view.layer.bounds
view.layer.addSublayer(video)
session.startRunning()
}
func metadataOutput(_ output: AVCaptureMetadataOutput, didOutput metadataObjects: [AVMetadataObject], from connection: AVCaptureConnection) {
if metadataObjects != nil && metadataObjects.count != nil {
if let object = metadataObjects.first as? AVMetadataMachineReadableCodeObject {
// if let object = metadataObjects[0] as? AVMetadataMachineReadableCodeObject {
if object.type == AVMetadataObject.ObjectType.qr {
let alert = UIAlertController(title: "QR code", message: object.stringValue, preferredStyle: UIAlertController.Style.alert)
alert.addAction(UIAlertAction(title: "Retake", style: UIAlertAction.Style.default, handler: nil))
alert.addAction(UIAlertAction(title: "Copy", style: UIAlertAction.Style.default, handler: { (nil) in
UIPasteboard.general.string = object.stringValue
}))
self.present(alert, animated: true, completion: nil)
}
}
}
}
}
Post
Replies
Boosts
Views
Activity
I would like to enumerate the files in iCloud drive or may be a specific folder chosen by the user, so that i can populate contents based on the files in the specific folder.
Is this possible with UIDocument or what is the way to do it?
when i run the wizard generated app, app creates document in the iphone local storage, but would like to start with creating document in the icloud storage storage so that it does not miss by accident..
how to configure app code to start with icloud drive
Hi,
Ever since I bought the developer account im not able to get straight forward support for this, please help how to get help on api's and working of it from forum..I have just now started to use the forum and started providing comments to other users, but meanwhile how to get help faster as a paid developer account holder ? I at least want to enjoy using apple code to start with. please help.
I want to create a file in icloud folder using filemanager,
i used the following code,
FileManager.default.url(forUbiquityContainerIdentifier: nil)?.appendingPathComponent("Documents").appendingPathComponent("String.txt")
do {
print("about to write")
		try testText.write(to: filemanUrl!, atomically: true, encoding: String.Encoding.utf8)
		print("after write")
} catch
{
print(error.localizedDescription)
}
but it is writing to a folder in
/Users/<myname>/Library/Developer/CoreSimulator/Devices/A3A4FF34-0942-4B9A-84F3-F4F6F48D4608/data/Library/Mobile Documents/iCloud~clouddrive/Documents