Swiftpack.co -  EFPrefix/EFQRCode as Swift Package
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
EFPrefix/EFQRCode
A better way to operate QR Code in Swift, support iOS, macOS, watchOS and tvOS.
.package(url: "https://github.com/EFPrefix/EFQRCode.git", from: "6.1.0")

Compatible with all Platforms

EFQRCode is a lightweight, pure-Swift library for generating stylized QRCode images with watermark or icon, and for recognizing QRCode from images, inspired by qrcode. Based on CoreGraphics, CoreImage, and ImageIO, EFQRCode provides you a better way to handle QRCode in your app, no matter if it is on iOS, macOS, watchOS, and/or tvOS. You can integrate EFQRCode through CocoaPods, Carthage, and/or Swift Package Manager.

中文介绍

Examples

Demo Projects

App Store

You can click the App Store button below to download demo, support iOS, tvOS and watchOS:

You can also click the Mac App Store button below to download demo for macOS:

Compile Demo Manually

To run the example project manually, clone the repo, demos are in the 'Examples' folder, remember run command sh Startup.sh in terminal to get all dependencies first, then open EFQRCode.xcworkspace with Xcode and select the target you want, run.

Or you can run the following command in terminal:

git clone git@github.com:EFPrefix/EFQRCode.git; cd EFQRCode; sh Startup.sh; open 'EFQRCode.xcworkspace'

Requirements

Version Needs
1.x Xcode 8.0+
Swift 3.0+
iOS 8.0+ / macOS 10.11+ / tvOS 9.0+
4.x Xcode 9.0+
Swift 4.0+
iOS 8.0+ / macOS 10.11+ / tvOS 9.0+ / watchOS 2.0+
5.x Xcode 11.1+
Swift 5.0+
iOS 8.0+ / macOS 10.11+ / tvOS 9.0+ / watchOS 2.0+
6.x Xcode 12.0+
Swift 5.1+
iOS 9.0+ / macOS 10.10+ / tvOS 9.0+ / watchOS 2.0+

Installation

CocoaPods

EFQRCode is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'EFQRCode', '~> 6.1.0'

Then, run the following command:

$ pod install

Carthage

IMPORTANT: this workaround is necessary for Carthage to somewhat work in Xcode 12.

Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.

You can install Carthage with Homebrew using the following command:

$ brew update
$ brew install carthage

To integrate EFQRCode into your Xcode project using Carthage, specify it in your Cartfile:

github "EFPrefix/EFQRCode" ~> 6.1.0

Run carthage update to build the framework and drag the built EFQRCode.framework into your Xcode project.

Swift Package Manager

The Swift Package Manager is a tool for automating the distribution of Swift code and is integrated into the Swift compiler.

Once you have your Swift package set up, adding EFQRCode as a dependency is as easy as adding it to the dependencies value of your Package.swift.

dependencies: [
    .package(url: "https://github.com/EFPrefix/EFQRCode.git", .upToNextMinor(from: "6.1.0"))
]

Quick Start

1. Import EFQRCode

Import EFQRCode module where you want to use it:

import EFQRCode

2. Recognition

A String Array is returned as there might be several QR Codes in a single CGImage:

if let testImage = UIImage(named: "test.png")?.cgImage {
    let codes = EFQRCode.recognize(testImage)
    if !codes.isEmpty {
        print("There are \(codes.count) codes")
        for (index, code) in codes.enumerated() {
            print("The content of QR Code \(index) is \(code).")
        }
    } else {
        print("There is no QR Codes in testImage.")
    }
}

3. Generation

Create QR Code image, basic usage:

Parameter Description
content REQUIRED, content of QR Code
size Width and height of image
backgroundColor Background color of QRCode
foregroundColor Foreground color of QRCode
watermark Background image of QRCode
if let image = EFQRCode.generate(
    for: "https://github.com/EFPrefix/EFQRCode",
    watermark: UIImage(named: "WWF")?.cgImage
) {
    print("Create QRCode image success \(image)")
} else {
    print("Create QRCode image failed!")
}

Result:

4. Generation from GIF

Use EFQRCode.generateGIF to create GIF QRCode.

Parameter Description
generator REQUIRED, an EFQRCodeGenerator instance with other settings
data REQUIRED, encoded input GIF
delay Output QRCode GIF delay, emitted means no change
loopCount Times looped in GIF, emitted means no change
if let qrCodeData = EFQRCode.generateGIF(
    using: generator, withWatermarkGIF: data
) {
    print("Create QRCode image success.")
} else {
    print("Create QRCode image failed!")
}

You can get more information from the demo, result will like this:

5. Next

Learn more from User Guide.

Recommendations

  1. Please select a high contrast foreground and background color combinations;
  2. To improve the definition of QRCode images, increase size, or scale up using magnification (instead);
  3. Magnification too high/size too large/contents too long may cause failure;
  4. It is recommended to test the QRCode image before put it into use;
  5. You can contact me if there is any problem, both Issue and Pull request are welcome.

PS of PS: I wish you can click the Star button if this tool is useful for you, thanks, QAQ...

Other Platforms/Languages

Platforms/Languages Link
Objective-C https://github.com/z624821876/YSQRCode
Java https://github.com/SumiMakito/AwesomeQRCode
JavaScript https://github.com/SumiMakito/Awesome-qr.js
Kotlin https://github.com/SumiMakito/AwesomeQRCode-Kotlin
Python https://github.com/sylnsfar/qrcode

Contributors

This project exists thanks to all the people who contribute. [Contribute]

PS: We use QRCodeSwift to generate QR code on watchOS, thanks to ApolloZhu.

Donations

If you think this project has brought you help, you can buy me a cup of coffee. If you like this project and are willing to provide further support for it's development, you can choose to become Backer or Sponsor in Open Collective.

Backers

Thank you to all our backers! 🙏 [Become a backer]

Sponsors

Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [Become a sponsor]

Thanks for your support, 🙏

Thanks

Apps using EFQRCode

Other

Part of the pictures in the demo project and guide come from the internet. If there is any infringement of your legitimate rights and interests, please contact us to delete.

Contact

Email: eyrefree@eyrefree.org

License

EFQRCode is available under the MIT license. See the LICENSE file for more info.

GitHub

link
Stars: 3968
Last commit: 5 weeks ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Release Notes

EFQRCode 6.1.0
5 weeks ago

Official V6 Release 🎉

This release contains breaking changes, in addition to those mentioned in v6.0.0!

Migration

Wonder what's new in this official V6 release? How do I fix those new warnings? Check out the migration guide here: https://github.com/EFPrefix/EFQRCode/discussions/115, or watch the video demonstration on YouTube 或者 bilibili.


Changelog

Add

  • Supports chaining EFQRCodeGenerator configuration methods.
  • EFQRCodeGenerator properties are now public.
  • EFQRCodeGenerator.clearCache can be used to free up memories used for caching results.
  • English documentation is now available through Xcode quick help.
  • Swift: EFWatermarkMode.rectForWatermark(ofSize:inCanvasOfSize:) can be used to calculate the frame for watermark image in a canvas.
  • Objective-C: New tests to ensure APIs are available in Objective-C.

Change

  • Renamed EFQRCodeGenerator configuration methods to be more consistent.
    • Renamed EFQRCode and reordered convenience generate function arguments to be consistent with generator methods.
  • EFQRCodeGenerator now caches more generated contents to improve performance.
  • EFQRCodeRecognizer expects non-nil image and returns non-nil array of results. The returned array may still be empty.
  • EFIntSize is now an immutable, final class.
  • Renamed CGColor extensions white and black to omit first argument label.
  • Objective-C: EFQRCodeGenerator and EFQRCodeRecognizer is now fully available to configure/use in Objective-C.

Deprecate

  • EFQRCodeMode.none is now deprecated. Use nil and EFQRCodeMode? instead.

Remove

  • EFUIntPixel is no longer a part of the public interface.
  • GIF generation no longer takes pathToSave parameter.
  • Objective-C: EFQRCode is no longer available in Objective-C. Use EFQRCodeGenerator and EFQRCodeRecognizer instead.

Release Notes from v6.0.0

Add

  • Add support to compile for macOS 10.10 using CocoaPods.

Change

  • QRCodeSwift (FKA swift_qrcodejs) is now conditional dependency with Swift Package Manager 5.3+.

Remove

  • Drop iOS 8 support from CocoaPods with Xcode 12 #101;
  • Remove Core and watchOS subspecs #100.
    • Please integrate EFQRCode directly instead of using subspecs.
    • QRCodeSwift should still be a conditional dependency for watchOS only.
What happened to semantic versioning?

Yes, I should have named release 6.0.0 as 6.0.0-rc.1, but I guess it's too late now :P

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API