-2

I just start learning IOS development recently. I am working on a group project, and with one of its function, I want to allow user to add friends through the scan of QR code, similar to WeChat and SnapChat apps. How do I do that?

All user's data is currently stored in Heroku Parse. It has a class of "User." There is a column (key) of "username."

Here is a picture of my Parse Database: https://i.stack.imgur.com/LKLCf.jpg

Here are some of the websites I found helpful: 1) How to retrieve all data from QR Code Swift 4 2) https://github.com/AvdLee/QR-Code-Custom 3) https://medium.com/itch-design-no/how-to-generate-qr-codes-in-ios-f24d49da6400

I found a few websites online that could be helpful, but they don't seem to be able to solve my issue directly. However, as a beginner IOS learner, I don't have enough skillset currently to design something tailor to what I need.

I want to allow user to add friend through the scan of QR code, so I think the QR code should be able to store the username. Each user should have only one unique QR code.

Kin Lay
  • 11

1 Answers1

0

Thank you everyone, I use this code instead:

import UIKit
import Parse

class QRAddContactViewController: UIViewController {

    var contactName: String?

    @IBOutlet weak var QRImage: UIImageView!

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        generatorQR()
    }

    override func viewDidAppear(_ animated: Bool) {
        generatorQR()
    }

    func generatorQR() {
        let query = PFUser.query()
        query?.whereKey("username", equalTo: PFUser.current()!.username!)

        query?.findObjectsInBackground(block: { (objects, error) in
            if error == nil {
                for object in objects! {
                    if object["username"] != nil {
                        self.contactName = object["username"] as? String
                        print(self.contactName!)
                    }}}})
        if let myString = self.contactName
        {
            let data = myString.data(using: .ascii, allowLossyConversion: false)
            let filter = CIFilter(name: "CIQRCodeGenerator")
            filter?.setValue(data, forKey: "InputMessage")
            let ciImage = filter?.outputImage
            let transform = CGAffineTransform(scaleX: 10, y: 10)
            let transformImage = ciImage?.transformed(by: transform)
            let image = UIImage(ciImage: transformImage!)
            QRImage.image = image
        }
    }
}
Kin Lay
  • 11