LoginSignup
19
19

More than 5 years have passed since last update.

Swift2.0でQRコードを出力する

Posted at

iOS7からQRコードを出力出来るようになりました。
iOS9になった今、WebViewが使えないiOSなんて無いと思いますがSwift2.0でもこの機能が使えるので、ちょっとおさらいです。

        let ciFilter = CIFilter(name: "CIQRCodeGenerator")
        ciFilter?.setDefaults()
        let qrString = "http://google.com"
        let data = qrString.dataUsingEncoding(NSUTF8StringEncoding)
        ciFilter?.setValue(data, forKey: "inputMessage")
        ciFilter?.setValue("L", forKey: "inputCorrectionLevel")
        let ciContext = CIContext()
        let cgimg = ciContext.createCGImage((ciFilter?.outputImage)!, fromRect: (ciFilter?.outputImage?.extent)!)
        let image = UIImage(CGImage: cgimg, scale: UIScreen.mainScreen().scale, orientation: UIImageOrientation.Up)
        imageView.image = image

いじょ!

19
19
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
19
19