14 Commits

Author SHA1 Message Date
Michael d1789afc70 remove text from progress view 2016-10-05 15:36:10 +03:00
Michael 78284c78ff update readme 2016-10-05 15:24:25 +03:00
Michael 8b7264e87b taking photos progress view 2016-10-05 15:17:02 +03:00
Michael 227d714c9a bug fix 2016-10-05 13:27:36 +03:00
Michael c2316cd1e5 improved example, fixed pod code 2016-10-04 12:36:01 +03:00
Michael 6c89e8b11c minor fixes 2016-09-30 19:21:52 +03:00
Michael 40d33b98c9 fix readme 2016-09-30 17:23:27 +03:00
Michael 9b32ba7415 refactoring + comments 2016-09-30 17:11:47 +03:00
Michael 813246b009 take multiple photos 2016-09-30 14:18:46 +03:00
Michael f43feb57c5 minor fixes 2016-09-28 20:20:25 +03:00
Michael 95d040fe7b taking multiple photos (poor alpha) 2016-09-28 19:34:02 +03:00
Michael 2cc54fa9fb swift 3 2016-09-28 14:57:31 +03:00
Michael f0d1638d5f remove unnecessary logs 2016-09-28 13:27:56 +03:00
Sergey Pronin 51682cd985 Update README.md 2016-09-27 12:17:33 +03:00
64 changed files with 6420 additions and 3739 deletions
+1 -1
View File
@@ -8,7 +8,7 @@
Pod::Spec.new do |s|
s.name = 'DocumentsOCR'
s.version = '0.6.1'
s.version = '1.0.0'
s.summary = 'A Swift framework for machine readable documents recognition'
# This description is used to generate tags and improve search results.
@@ -13,11 +13,11 @@
</placeholder>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<view clearsContextBeforeDrawing="NO" contentMode="scaleToFill" id="i5M-Pr-FkT" customClass="CameraOverlayView" customModule="DocumentsOCR" customModuleProvider="target">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<rect key="frame" x="0.0" y="0.0" width="320" height="480"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" id="cm0-0M-N08">
<frame key="frameInset" minX="50.00%" width="81" height="80" maxY="8"/>
<frame key="frameInset" minX="49.38%" width="79" height="78" maxY="10"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxX="YES" flexibleMinY="YES"/>
<state key="normal" title="Сканировать" image="circle.png"/>
<connections>
@@ -25,7 +25,7 @@
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" id="Sft-Iw-wJR">
<frame key="frameInset" minX="16" width="60" height="60" maxY="8"/>
<frame key="frameInset" minX="16" width="60" height="59" maxY="10"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<state key="normal" title="Отмена" image="cancel.png"/>
<connections>
@@ -33,10 +33,28 @@
</connections>
</button>
<view contentMode="scaleToFill" misplaced="YES" id="aq8-eL-xhw">
<frame key="frameInset" minY="49.91%" height="90"/>
<frame key="frameInset" minX="-1" minY="49.61%" height="91" maxX="2"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMinY="YES" flexibleMaxY="YES"/>
<color key="backgroundColor" red="0.65969551282051275" green="0.18069087995348332" blue="0.19548233647129598" alpha="0.37365301724137934" colorSpace="custom" customColorSpace="sRGB"/>
</view>
<view hidden="YES" contentMode="scaleToFill" misplaced="YES" id="d9X-cr-gxH">
<frame key="frameInset" minX="15" minY="31.16%" height="50" maxX="16"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMinY="YES" flexibleMaxY="YES"/>
<subviews>
<progressView opaque="NO" contentMode="scaleToFill" verticalHuggingPriority="750" misplaced="YES" id="tty-uX-5VZ">
<frame key="frameInset" minX="7" minY="85.42%" height="2" maxX="10"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMinY="YES" flexibleMaxY="YES"/>
</progressView>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" misplaced="YES" text="" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="rYM-tc-tec">
<frame key="frameInset" minX="2.42%" minY="25.00%" width="94.81%" height="22"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" widthSizable="YES" flexibleMaxX="YES" flexibleMinY="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<color key="backgroundColor" red="0.66644631410256405" green="0.63874751166677468" blue="0.63933249441946849" alpha="0.79617456896551719" colorSpace="calibratedRGB"/>
</view>
</subviews>
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="number" keyPath="borderWidth">
@@ -45,17 +63,21 @@
</userDefinedRuntimeAttributes>
<connections>
<outlet property="codeBorder" destination="aq8-eL-xhw" id="HIf-dd-a4H"/>
<outlet property="progressLabel" destination="rYM-tc-tec" id="x6f-4X-I6p"/>
<outlet property="progressView" destination="tty-uX-5VZ" id="9ob-2H-wwl"/>
<outlet property="progressViewContainer" destination="d9X-cr-gxH" id="Dpp-QJ-560"/>
<outlet property="takePhotoButton" destination="cm0-0M-N08" id="H5X-vT-mNc"/>
</connections>
<point key="canvasLocation" x="421.5" y="462.5"/>
<point key="canvasLocation" x="420.5" y="461.5"/>
</view>
</objects>
<resources>
<image name="cancel.png" width="52" height="52"/>
<image name="cancel.png" width="104" height="104"/>
<image name="circle.png" width="256" height="256"/>
</resources>
<simulatedMetricsContainer key="defaultSimulatedMetrics">
<simulatedStatusBarMetrics key="statusBar"/>
<simulatedOrientationMetrics key="orientation"/>
<simulatedScreenMetrics key="destination" type="retina4_7.fullscreen"/>
<simulatedScreenMetrics key="destination"/>
</simulatedMetricsContainer>
</document>
@@ -8,18 +8,31 @@
import UIKit
public class CameraOverlayView: UIView {
protocol CameraViewDelegate {
func stopTakingPictures()
func startTakingPictures()
}
open class CameraOverlayView: UIView {
@IBOutlet weak var codeBorder: UIView!
@IBOutlet weak var takePhotoButton: UIButton!
var scanner: DocumentScanner!
@IBOutlet weak var progressLabel: UILabel!
@IBOutlet weak var progressView: UIProgressView!
@IBOutlet weak var progressViewContainer: UIView!
@IBAction func cancelButtonClicked(sender: UIButton) {
scanner.containerViewController.dismissViewControllerAnimated(true, completion: nil)
var delegate: CameraViewDelegate!
@IBAction func cancelButtonClicked(_ sender: UIButton) {
resetViews()
delegate.stopTakingPictures()
}
@IBAction func scanButtonClicked(sender: UIButton) {
scanner.imagePicker.takePicture()
@IBAction func scanButtonClicked(_ sender: UIButton) {
takePhotoButton.isHidden = true
progressViewContainer.isHidden = false
delegate.startTakingPictures()
}
override init(frame: CGRect) {
@@ -28,6 +41,13 @@ public class CameraOverlayView: UIView {
required public init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)!
self.opaque = false
self.isOpaque = false
}
func resetViews() {
takePhotoButton.isHidden = false
progressLabel.text = ""
progressView.progress = 0
progressViewContainer.isHidden = true
}
}
@@ -8,8 +8,4 @@
import UIKit
class CameraOverlayViewController: UIViewController {
override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
return .Portrait
}
}
class CameraOverlayViewController: UIViewController {}
@@ -8,24 +8,25 @@
import Foundation
let simpleFormatter: NSDateFormatter = {
let formatter = NSDateFormatter()
let simpleFormatter: DateFormatter = {
let formatter = DateFormatter()
formatter.dateFormat = "yyyy-MM-dd"
formatter.timeZone = NSTimeZone(forSecondsFromGMT: 0)
formatter.timeZone = TimeZone(secondsFromGMT: 0)
return formatter
}()
extension NSDate {
static func dateFromPassportDateCode(code: String) -> NSDate? {
let year = code[0...3]
let month = code[4...5]
let day = code[6...7]
return simpleFormatter.dateFromString("\(year)-\(month)-\(day)")
extension Date {
static func dateFromPassportDateCode(_ code: String) -> Date? {
let year = code.substring(from: 0, to: 3)
let month = code.substring(from: 4, to: 5)
let day = code.substring(from: 6, to: 7)
return simpleFormatter.date(from: "\(year)-\(month)-\(day)")
}
var stringDate: String {
return simpleFormatter.stringFromDate(self)
return simpleFormatter.string(from: self)
}
}
@@ -10,8 +10,8 @@ import Foundation
extension NSTextCheckingResult {
func group(atIndex index: Int, fromSource source: String) -> String {
let range = self.rangeAtIndex(index)
return (source as NSString).substringWithRange(range).stringByTrimmingCharactersInSet(NSCharacterSet(charactersInString: "<"))
let range = self.rangeAt(index)
return (source as NSString).substring(with: range).trimmingCharacters(in: CharacterSet(charactersIn: "<"))
}
}
@@ -3,16 +3,58 @@ import Foundation
extension String {
subscript (i: Int) -> Character {
return self[self.startIndex.advancedBy(i)]
let index = self.index(self.startIndex, offsetBy: i)
return self.characters[index]
}
subscript (i: Int) -> String {
return String(self[i] as Character)
func substring(from: Int, to: Int) -> String {
let fromIndex = self.index(self.startIndex, offsetBy: from)
let toIndex = self.index(self.startIndex, offsetBy: to + 1)
return self.substring(with: fromIndex ..< toIndex)
}
subscript (r: Range<Int>) -> String {
let start = startIndex.advancedBy(r.startIndex)
let end = start.advancedBy(r.endIndex - r.startIndex)
return self[Range(start ..< end)]
func replaceNumbers() -> String {
var result = ""
for char in self.characters {
switch char {
case "0": result.append("O")
case "1": result.append("I")
case "2": result.append("S")
case "3": result.append("S")
case "4": result.append("A")
case "5": result.append("S")
case "6": result.append("G")
case "7": result.append("Z")
case "8",
"9": result.append("B")
default: result.append(char)
}
}
return result
}
func replaceLetters() -> String {
var result = ""
for char in self.characters {
switch char {
case "O",
"D": result.append("0")
case "I",
"L": result.append("1")
case "S": result.append("5")
case "A": result.append("4")
case "G": result.append("6")
case "Z": result.append("7")
case "B": result.append("8")
default: result.append(char)
}
}
return result
}
}
@@ -11,21 +11,21 @@ import UIKit
import GPUImage
extension UIImage {
func croppedImageWithSize(rect: CGRect) -> UIImage {
func croppedImageWithSize(_ rect: CGRect) -> UIImage {
let imageRef: CGImageRef! = CGImageCreateWithImageInRect(self.CGImage!, rect)
let imageRef: CGImage! = self.cgImage!.cropping(to: rect)
let croppedImage: UIImage = UIImage(CGImage: imageRef, scale: self.scale, orientation: self.imageOrientation)
let croppedImage: UIImage = UIImage(cgImage: imageRef, scale: self.scale, orientation: self.imageOrientation)
let selectedFilter = GPUImageTransformFilter()
selectedFilter.setInputRotation(kGPUImageNoRotation, atIndex: 0)
let image: UIImage = selectedFilter.imageByFilteringImage(croppedImage)
selectedFilter.setInputRotation(kGPUImageNoRotation, at: 0)
let image: UIImage = selectedFilter.image(byFilteringImage: croppedImage)
return image
}
func save(path: String) {
func save(_ path: String) {
let png = UIImagePNGRepresentation(self)
png?.writeToFile(path, atomically: true)
try? png?.write(to: URL(fileURLWithPath: path), options: [.atomic])
}
}
+13 -9
View File
@@ -8,28 +8,32 @@
import Foundation
public let DOErrorDomain = "DocumentsOCRErrorDomain"
public struct DOErrorCodes {
public static let recognize = 0
public static let noCamera = 1
}
struct NibNames {
static let cameraOverlayViewController = "CameraOverlayViewController"
}
struct Constants {
public struct DOConstants {
public static let errorDomain = "DocumentsOCRErrorDomain"
static let alphabet = Constants.getAlphabet()
private static func getAlphabet() -> String {
static let alphabet: String = {
let aScalars = "a".unicodeScalars
let aCode = aScalars[aScalars.startIndex].value
var result = ""
for i: UInt32 in (0..<26) {
result.append(Character(UnicodeScalar(aCode + i)))
for i: UInt32 in (0 ..< 26) {
result.append(Character(UnicodeScalar(aCode + i)!))
}
return result
}
}()
}
+91 -6
View File
@@ -7,11 +7,96 @@
//
import Foundation
import TesseractOCR
import PodAsset
public class Utils {
public static func stringFromTxtFile(fileName: String, inBundle bundle: NSBundle = NSBundle.mainBundle()) -> String? {
let filePath = bundle.pathForResource(fileName, ofType: "txt")
let contentData = NSFileManager.defaultManager().contentsAtPath(filePath!)
return NSString(data: contentData!, encoding: NSUTF8StringEncoding) as? String
open class Utils {
fileprivate static let bundle = PodAsset.bundle(forPod: "DocumentsOCR")!
static let passportPattern: String! = Utils.stringFromTxtFile("passportPattern", inBundle: bundle)
fileprivate static let tesseract = createTesseract()
open static func stringFromTxtFile(_ fileName: String, inBundle bundle: Bundle = Bundle.main) -> String? {
let filePath = bundle.path(forResource: fileName, ofType: "txt")
let contentData = FileManager.default.contents(atPath: filePath!)
return NSString(data: contentData!, encoding: String.Encoding.utf8.rawValue) as? String
}
}
static func mrCodeFrom(image: UIImage, tesseractDelegate: G8TesseractDelegate? = nil) -> String? {
let path = bundle.path(forResource: "eng", ofType: "traineddata")
tesseract.delegate = tesseractDelegate!
tesseract.image = image
tesseract.recognize()
if let recognizedText = tesseract.recognizedText {
NSLog("Recognized: \(recognizedText)")
let text = recognizedText.replacingOccurrences(of: " ", with: "")
let regex = try? NSRegularExpression(pattern: passportPattern, options: [])
let range = NSRange(location: 0, length: text.characters.count)
if let result = regex!.firstMatch(in: text, options: [], range: range) {
let code = (text as NSString).substring(with: result.range)
return fixFirstRowIn(code: code)
}
}
return nil
}
fileprivate static func fixFirstRowIn(code: String) -> String {
let pattern = "(?<FirstLine>(?<Passport>[A-Z0-9])(?<PassportType>.)(?<IssuingCountry>[A-Z0-9]{3})(?<PassportOwner>(?<Surname>[A-Z0-9]+)<<(?<GivenName>(?:[A-Z0-9]+<)+)){1})"
let regex = try? NSRegularExpression(pattern: pattern, options: [])
let range = NSRange(location: 0, length: code.characters.count)
let result = regex!.matches(in: code, options: [], range: range)
var resultFirstRow = (code as NSString).substring(with: result[0].range)
while resultFirstRow.characters.count != 44 {
resultFirstRow.append("<")
}
let secondRow = code.characters.split(separator: "\n", maxSplits: 2, omittingEmptySubsequences: true)[1]
return "\(resultFirstRow)\n\(String(secondRow))\n"
}
fileprivate static func createTesseract() -> G8Tesseract {
let trainDataPath = bundle.path(forResource: "eng", ofType: "traineddata")
let cacheURL = FileManager.default.urls(for: .cachesDirectory, in: .userDomainMask).first!
let tessdataURL = cacheURL.appendingPathComponent("tesseract", isDirectory: true).appendingPathComponent("tessdata", isDirectory: true)
let destinationURL = tessdataURL.appendingPathComponent("eng.traineddata")
if !FileManager.default.fileExists(atPath: destinationURL.path) {
createTessdataFrom(trainDataPath!, toDirectoryURL: tessdataURL, withDestinationURL: destinationURL)
}
let tesseract = G8Tesseract(language: "eng", configDictionary: [:], configFileNames: [], absoluteDataPath: tessdataURL.path, engineMode: .tesseractOnly, copyFilesFromResources: false)
var whiteList = DOConstants.alphabet.uppercased()
whiteList.append("<>1234567890")
tesseract?.charWhitelist = whiteList
tesseract?.setVariableValue("FALSE", forKey: "x_ht_quality_check")
return tesseract!
}
fileprivate static func createTessdataFrom(_ filePath: String, toDirectoryURL tessdataURL: URL, withDestinationURL destinationURL: URL) {
do {
let fileManager = FileManager.default
try fileManager.createDirectory(atPath: tessdataURL.path,
withIntermediateDirectories: true, attributes: nil)
try fileManager.copyItem(atPath: filePath, toPath: destinationURL.path)
}
catch let error as NSError {
assertionFailure("There is no tessdata directory in cache (TesseractOCR traineddata). \(error.localizedDescription)")
}
}
}
+27 -105
View File
@@ -10,9 +10,9 @@ import Foundation
import TesseractOCR
import PodAsset
///gender
/// Gender enumeration
public enum Gender {
case Male, Female, Unknown
case male, female, unknown
}
/// Struct-container for recognition fields of passport machine readable code
@@ -35,13 +35,13 @@ public struct DocumentInfo {
public let nationalityCode: String
/// Date of birth
public let dateOfBirth: NSDate?
public let dateOfBirth: Date?
/// Gender
public let gender: Gender
/// Expiration date of passport
public let expirationDate: NSDate?
public let expirationDate: Date?
/// Personal number (may be used by the issuing country as it desires)
public let personalNumber: String
@@ -49,141 +49,63 @@ public struct DocumentInfo {
/// Check digits (0-9, also can be "<")
public let checkDigits: [String]
private static let bundle = PodAsset.bundleForPod("DocumentsOCR")
private static let passportPattern: String! = Utils.stringFromTxtFile("passportPattern", inBundle: bundle)
let mrCode: String
init?(recognizedText text: String) {
let regex: NSRegularExpression
do {
regex = try NSRegularExpression(pattern: DocumentInfo.passportPattern, options: [])
}
catch {
NSLog("error pattern")
return nil
}
let regex = try! NSRegularExpression(pattern: Utils.passportPattern, options: [])
let range = NSRange(location: 0, length: text.characters.count)
if let result = regex.firstMatchInString(text, options: [], range: range) {
NSLog("\(result.components)")
if let result = regex.firstMatch(in: text, options: [], range: range) {
issuingCountryCode = result.group(atIndex: 4, fromSource: text)
lastname = result.group(atIndex: 6, fromSource: text)
name = result.group(atIndex: 7, fromSource: text).stringByReplacingOccurrencesOfString("<", withString: " ")
mrCode = (text as NSString).substring(with: result.range)
issuingCountryCode = result.group(atIndex: 4, fromSource: text).replaceNumbers()
lastname = result.group(atIndex: 6, fromSource: text).replaceNumbers()
name = result.group(atIndex: 7, fromSource: text).replacingOccurrences(of: "<", with: " ").replaceNumbers()
passportNumber = result.group(atIndex: 9, fromSource: text)
nationalityCode = result.group(atIndex: 11, fromSource: text)
nationalityCode = result.group(atIndex: 11, fromSource: text).replaceNumbers()
let dayOfBirthCode = result.group(atIndex: 12, fromSource: text)
dateOfBirth = NSDate.dateFromPassportDateCode("19" + dayOfBirthCode)
let dayOfBirthCode = result.group(atIndex: 12, fromSource: text).replaceLetters()
dateOfBirth = Date.dateFromPassportDateCode("19" + dayOfBirthCode)
let genderLetter = result.group(atIndex: 17, fromSource: text)
switch genderLetter {
case "F":
gender = .Female
gender = .female
case "M":
gender = .Male
gender = .male
default:
NSLog("Error: unknown sex \(genderLetter)")
gender = .Unknown
gender = .unknown
}
let expiralDateCode = result.group(atIndex: 18, fromSource: text)
expirationDate = NSDate.dateFromPassportDateCode("20" + expiralDateCode)
let expiralDateCode = result.group(atIndex: 18, fromSource: text).replaceLetters()
expirationDate = Date.dateFromPassportDateCode("20" + expiralDateCode)
personalNumber = result.group(atIndex: 23, fromSource: text)
checkDigits = [
result.group(atIndex: 10, fromSource: text),
result.group(atIndex: 16, fromSource: text),
result.group(atIndex: 22, fromSource: text),
result.group(atIndex: 24, fromSource: text),
result.group(atIndex: 25, fromSource: text),
result.group(atIndex: 10, fromSource: text).replaceLetters(),
result.group(atIndex: 16, fromSource: text).replaceLetters(),
result.group(atIndex: 22, fromSource: text).replaceLetters(),
result.group(atIndex: 24, fromSource: text).replaceLetters(),
result.group(atIndex: 25, fromSource: text).replaceLetters()
]
}
else {
NSLog("Error: no match result")
return nil
}
}
init?(image: UIImage, tesseractDelegate: G8TesseractDelegate? = nil) {
let path = DocumentInfo.bundle.pathForResource("eng", ofType: "traineddata")
NSLog("Train data path: \(path)")
let tesseract = DocumentInfo.tesseract
let cacheURL = NSFileManager.defaultManager().URLsForDirectory(.CachesDirectory, inDomains: .UserDomainMask).first!
let tessdataPath = cacheURL.absoluteString! + "tessdata"
do {
let fileManager = NSFileManager.defaultManager()
try fileManager.createDirectoryAtPath(tessdataPath, withIntermediateDirectories: true, attributes: nil)
try fileManager.copyItemAtPath(path!, toPath: tessdataPath)
NSLog("Tessdata in cache: \(fileManager.fileExistsAtPath(tessdataPath + "eng.traineddata"))")
NSLog("end")
}
catch {
NSLog("Create folder error!")
}
NSLog("Tess absolute path : \(tesseract.absoluteDataPath)")
NSLog("folder: \(DocumentInfo.bundle.resourcePath)")
tesseract.delegate = tesseractDelegate!
tesseract.image = image
tesseract.recognize()
if let recognizedText = tesseract.recognizedText {
NSLog("RECOGNIZED: \(recognizedText)")
let mrCode = recognizedText.stringByReplacingOccurrencesOfString(" ", withString: "")
if let mrCode = Utils.mrCodeFrom(image: image, tesseractDelegate: tesseractDelegate) {
NSLog("Recognized: \(mrCode)")
self.init(recognizedText: mrCode)
}
else {
return nil
}
}
private static var tesseract: G8Tesseract = {
let trainDataPath = DocumentInfo.bundle.pathForResource("eng", ofType: "traineddata")
let cacheURL = NSFileManager.defaultManager().URLsForDirectory(.CachesDirectory, inDomains: .UserDomainMask).first!
let tessdataURL = cacheURL.URLByAppendingPathComponent("tesseract", isDirectory: true)!.URLByAppendingPathComponent("tessdata", isDirectory: true)!
let destinationURL = tessdataURL.URLByAppendingPathComponent("eng.traineddata")!
if !NSFileManager.defaultManager().fileExistsAtPath(destinationURL.path!) {
DocumentInfo.createTessdataFrom(trainDataPath!, toDirectoryURL: tessdataURL, withDestinationURL: destinationURL)
}
let tesseract = G8Tesseract(language: "eng", configDictionary: [:], configFileNames: [], absoluteDataPath: tessdataURL.path!, engineMode: .TesseractOnly, copyFilesFromResources: false)
var whiteList = Constants.alphabet.uppercaseString
whiteList.appendContentsOf("<>1234567890")
tesseract.charWhitelist = whiteList
tesseract.setVariableValue("FALSE", forKey: "x_ht_quality_check")
return tesseract
}()
private static func createTessdataFrom(filePath: String, toDirectoryURL tessdataURL: NSURL, withDestinationURL destinationURL: NSURL) {
do {
let fileManager = NSFileManager.defaultManager()
try fileManager.createDirectoryAtPath(tessdataURL.path!,
withIntermediateDirectories: true, attributes: nil)
try fileManager.copyItemAtPath(filePath, toPath: destinationURL.path!)
NSLog("Tessdata in cache: \(fileManager.fileExistsAtPath(destinationURL.path!))")
NSLog("end")
}
catch let error as NSError {
NSLog("Create folder error! \(error.localizedDescription)")
assertionFailure()
}
}
}
@@ -12,40 +12,59 @@ import PodAsset
/// The delegate of a DocumentScaner object must adopt the DocumentScannerDelegate protocol. Methods of protocol allow use result of document machine readable code recognition, handle errors if something went wrong. In addition, this protocol inherit G8TesseractDelegate protocol, so you can handle progress of image recognition (optional).
public protocol DocumentScannerDelegate: G8TesseractDelegate {
/// Tells the delegate that user press take photo button, contains reference to cropped image from camera shoot
///
/// - parameter scanner: The document scanner object informing the delegate of this event
/// - parameter image: The cropped image from camera shoot
func documentScanner(scanner: DocumentScanner, willBeginScanningImage image: UIImage)
/// - parameter images: The cropped images from camera shoots
func documentScanner(_ scanner: DocumentScanner, willBeginScanningImages: [UIImage])
/// Tells the delegate that progress of photos recognition changed
///
/// - parameter scanner: The document scanner object informing the delegate of this event
/// - parameter progress: progress value from 0.0 to 1.0
func documentScanner(_ scanner: DocumentScanner, recognitionProgress progress: Double)
/// Tells the delegate that scanner finished to recognize machine readable code from camera image and translate it into DocumentInfo struct
///
/// - parameter scanner: The document scanner object informing the delegate of this event
/// - parameter info: The document info object containing information of document from camera shoot
func documentScanner(scanner: DocumentScanner, didFinishScanningWithInfo info: DocumentInfo)
func documentScanner(_ scanner: DocumentScanner, didFinishScanningWithInfo info: DocumentInfo)
/// Tells the delegate that some error happened
///
/// - parameter scanner: The document scanner object informing the delegate of this event
/// - parameter error: The error object containing reason of failure
func documentScanner(scanner: DocumentScanner, didFailWithError error: NSError)
func documentScanner(_ scanner: DocumentScanner, didFailWithError error: NSError)
}
public class DocumentScanner: NSObject {
open class DocumentScanner: NSObject {
var imagePicker = UIImagePickerController()
/// View controller, which will present camera image picker for document machine readable code
public var containerViewController: UIViewController!
open var containerViewController: UIViewController!
/// The object that acts as the delegate of the document scanner
public var delegate: DocumentScannerDelegate!
open var delegate: DocumentScannerDelegate!
private let queue: NSOperationQueue = {
let queue = NSOperationQueue()
queue.qualityOfService = .UserInitiated
/// Number of photos to recognize
open var photosCount: UInt8 = 5
/// Time interval between taking photos
open var takePhotoInterval = 0.2
/// Recognized document information from RecognitionOperation
open var recognizedDocumentInfo: DocumentInfo? = nil
var timer: Timer!
var codes = [String]()
var images = [UIImage]()
var recognizedInfo: DocumentInfo? = nil
fileprivate let queue: OperationQueue = {
let queue = OperationQueue()
queue.qualityOfService = .userInitiated
queue.name = "ScannerOperationQueue"
return queue
}()
@@ -58,7 +77,7 @@ public class DocumentScanner: NSObject {
- Returns: The document scanner instance
*/
public init(containerVC: UIViewController, withDelegate delegate: DocumentScannerDelegate) {
self.delegate = delegate
self.containerViewController = containerVC
@@ -66,12 +85,12 @@ public class DocumentScanner: NSObject {
/// Present view controller with camera and border for document machine readable code
public func presentCameraViewController() {
if UIImagePickerController.availableCaptureModesForCameraDevice(.Rear) != nil {
open func presentCameraViewController() {
if UIImagePickerController.availableCaptureModes(for: .rear) != nil {
imagePicker = UIImagePickerController()
imagePicker.allowsEditing = false
imagePicker.sourceType = .Camera
imagePicker.cameraCaptureMode = .Photo
imagePicker.sourceType = .camera
imagePicker.cameraCaptureMode = .photo
imagePicker.showsCameraControls = false
imagePicker.delegate = self
@@ -82,37 +101,61 @@ public class DocumentScanner: NSObject {
let frame = CGRect(x: 0, y: 0, width: width, height: height)
overlayView.frame = frame
imagePicker.modalPresentationStyle = .FullScreen
containerViewController.presentViewController(imagePicker, animated: true, completion: {
imagePicker.modalPresentationStyle = .fullScreen
containerViewController.present(imagePicker, animated: true, completion: {
overlayView.codeBorder.layer.borderWidth = 5.0
overlayView.codeBorder.layer.borderColor = UIColor.redColor().CGColor
overlayView.codeBorder.layer.borderColor = UIColor.red.cgColor
overlayView.scanner = self
overlayView.delegate = self
overlayView.resetViews()
self.imagePicker.cameraOverlayView = overlayView
})
}
else {
let error = NSError(domain: DOErrorDomain, code: 1, userInfo: [
let error = NSError(domain: DOConstants.errorDomain, code: DOErrorCodes.noCamera, userInfo: [
NSLocalizedDescriptionKey : "Scanner unnable to find camera on this device"
])
self.delegate.documentScanner(self, didFailWithError: error)
delegate.documentScanner(self, didFailWithError: error)
}
}
open func cancelRecognizeOperation() {
queue.cancelAllOperations()
}
private var cameraOverlayView: CameraOverlayView {
let bundle = PodAsset.bundleForPod("DocumentsOCR")
fileprivate var cameraOverlayView: CameraOverlayView = {
let bundle = PodAsset.bundle(forPod: "DocumentsOCR")
let cameraVC = CameraOverlayViewController(nibName: NibNames.cameraOverlayViewController, bundle: bundle!)
let overlayView = cameraVC.view as! CameraOverlayView
return overlayView
}()
}
extension DocumentScanner: CameraViewDelegate {
func stopTakingPictures() {
timer.invalidate()
containerViewController.dismiss(animated: true, completion: nil)
}
func startTakingPictures() {
codes = [String]()
images = [UIImage]()
timer = Timer.scheduledTimer(timeInterval: takePhotoInterval, target: self, selector: #selector(self.timerTick(sender:)), userInfo: nil, repeats: true)
}
func timerTick(sender: Timer) {
imagePicker.takePicture()
}
}
extension DocumentScanner: UIImagePickerControllerDelegate, UINavigationControllerDelegate {
public func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
public func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
let editedImage = info[UIImagePickerControllerEditedImage] as? UIImage
let originalImage = info[UIImagePickerControllerOriginalImage] as! UIImage
@@ -121,32 +164,39 @@ extension DocumentScanner: UIImagePickerControllerDelegate, UINavigationControll
let cropped = cropImage(image)
containerViewController.dismissViewControllerAnimated(true, completion: nil)
images.append(cropped)
delegate.documentScanner(self, willBeginScanningImage: cropped)
cameraOverlayView.progressView.progress = Float(images.count) / Float(photosCount)
cameraOverlayView.progressLabel.text = "\(images.count) / \(photosCount)"
queue.addOperationWithBlock {
let infoOpt = DocumentInfo(image: cropped, tesseractDelegate: self.delegate)
if images.count >= Int(photosCount) {
stopTakingPictures()
dispatch_async(dispatch_get_main_queue()) {
if let info = infoOpt {
self.delegate.documentScanner(self, didFinishScanningWithInfo: info)
}
else {
let error = NSError(domain: DOErrorDomain, code: 0, userInfo: [
NSLocalizedDescriptionKey : "Scanner has failed to recognize machine readable code from camera picture"
])
self.delegate.documentScanner(self, didFailWithError: error)
cameraOverlayView.resetViews()
delegate.documentScanner(self, willBeginScanningImages: images)
let recognizeOperation = RecognizeOperation(scanner: self)
recognizeOperation.completionBlock = {
DispatchQueue.main.async {
if let info = self.recognizedInfo {
self.delegate.documentScanner(self, didFinishScanningWithInfo: info)
}
else {
let error = NSError(domain: DOConstants.errorDomain, code: DOErrorCodes.recognize, userInfo: [
NSLocalizedDescriptionKey : "Scanner has failed to recognize machine readable code from camera pictures"
])
self.delegate.documentScanner(self, didFailWithError: error)
}
}
}
queue.addOperation(recognizeOperation)
}
}
private func cropImage(image: UIImage) -> UIImage {
NSLog("image size: \(image.size)")
NSLog("vc size: \(containerViewController.view.frame.size)")
NSLog("border size: \(cameraOverlayView.codeBorder.frame.size)")
fileprivate func cropImage(_ image: UIImage) -> UIImage {
let viewControllerSize = containerViewController.view.frame.size
let vcWidth = viewControllerSize.width
@@ -160,9 +210,8 @@ extension DocumentScanner: UIImagePickerControllerDelegate, UINavigationControll
let cameraImageY = (cameraImageHeight - borderHeight) / 2
let rect = CGRectMake(cameraImageY, 0, borderHeight, image.size.width)
let rect = CGRect(x: cameraImageY, y: 0, width: borderHeight, height: image.size.width)
return image.croppedImageWithSize(rect)
}
}
@@ -0,0 +1,86 @@
//
// RecognitionOperation.swift
// Pods
//
// Created by Михаил on 01.10.16.
//
//
import Foundation
class RecognizeOperation: Operation {
let scanner: DocumentScanner
var codes = [String]()
init (scanner: DocumentScanner) {
self.scanner = scanner
}
override func main() {
let images = scanner.images
for index in 0 ..< images.count {
let image = images[index]
if isCancelled {
return
}
if let code = Utils.mrCodeFrom(image: image, tesseractDelegate: scanner.delegate) {
codes.append(code)
}
let progress = Double(index + 1) / Double(images.count)
DispatchQueue.main.async {
self.scanner.delegate.documentScanner(self.scanner, recognitionProgress: progress)
}
}
if codes.count == 0 {
return
}
var resultCode = ""
let count = codes.first!.characters.count
for index in 0 ..< count {
if isCancelled {
return
}
let winnerCharacter = chooseCharacterByVotesOn(index: index)
resultCode.append(winnerCharacter)
}
if isCancelled {
return
}
if let info = DocumentInfo(recognizedText: resultCode) {
scanner.recognizedInfo = info
}
}
fileprivate func chooseCharacterByVotesOn(index: Int) -> Character {
let characters = codes.map({ $0[index] })
var voting = [Character : Int]()
for character in characters {
if let count = voting[character] {
voting[character] = count + 1
}
else {
voting[character] = 1
}
}
let max = voting.values.max()!
for (character, count) in voting {
if count == max {
return character
}
}
return characters.first!
}
}
+10 -4
View File
@@ -437,6 +437,7 @@
607FACED1AFB9204008FA782 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LIBRARY = "libc++";
@@ -456,6 +457,7 @@
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
COPY_PHASE_STRIP = NO;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
EMBED_ASSET_PACKS_IN_PRODUCT_BUNDLE = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
@@ -484,6 +486,7 @@
607FACEE1AFB9204008FA782 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LIBRARY = "libc++";
@@ -503,6 +506,7 @@
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
COPY_PHASE_STRIP = NO;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
EMBED_ASSET_PACKS_IN_PRODUCT_BUNDLE = NO;
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
@@ -529,6 +533,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
DEVELOPMENT_TEAM = FECH3P2YXH;
ENABLE_BITCODE = NO;
INFOPLIST_FILE = DocumentsOCR/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
@@ -536,7 +541,7 @@
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE = "";
SWIFT_VERSION = 2.3;
SWIFT_VERSION = 3.0;
};
name = Debug;
};
@@ -548,6 +553,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
DEVELOPMENT_TEAM = FECH3P2YXH;
ENABLE_BITCODE = NO;
INFOPLIST_FILE = DocumentsOCR/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
@@ -555,7 +561,7 @@
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE = "";
SWIFT_VERSION = 2.3;
SWIFT_VERSION = 3.0;
};
name = Release;
};
@@ -573,7 +579,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 2.3;
SWIFT_VERSION = 3.0;
};
name = Debug;
};
@@ -587,7 +593,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 2.3;
SWIFT_VERSION = 3.0;
};
name = Release;
};
+7 -6
View File
@@ -6,6 +6,7 @@
// Copyright (c) 2016 Michael. All rights reserved.
//
import UIKit
@UIApplicationMain
@@ -14,31 +15,31 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
return true
}
func applicationWillResignActive(application: UIApplication) {
func applicationWillResignActive(_ application: UIApplication) {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}
func applicationDidEnterBackground(application: UIApplication) {
func applicationDidEnterBackground(_ application: UIApplication) {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}
func applicationWillEnterForeground(application: UIApplication) {
func applicationWillEnterForeground(_ application: UIApplication) {
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}
func applicationDidBecomeActive(application: UIApplication) {
func applicationDidBecomeActive(_ application: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}
func applicationWillTerminate(application: UIApplication) {
func applicationWillTerminate(_ application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
+25 -25
View File
@@ -27,10 +27,10 @@
<rect key="frame" x="0.0" y="154" width="375" height="66"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="w3V-S6-g0i" id="1Uf-5t-o32">
<frame key="frameInset" width="375" height="65"/>
<frame key="frameInset" width="375" height="66"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Выпускающая страна" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="I40-Fm-A5V">
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Issuing country" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="I40-Fm-A5V">
<constraints>
<constraint firstAttribute="width" constant="178" id="f89-jB-9ku"/>
</constraints>
@@ -72,10 +72,10 @@
<rect key="frame" x="0.0" y="220" width="375" height="66"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="QvW-RM-RVb" id="QSb-Su-7po">
<frame key="frameInset" width="375" height="65"/>
<frame key="frameInset" width="375" height="66"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Фамилия" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="2G4-OG-gF8">
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Last name" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="2G4-OG-gF8">
<constraints>
<constraint firstAttribute="width" constant="160" id="Lng-KN-xof"/>
</constraints>
@@ -117,10 +117,10 @@
<rect key="frame" x="0.0" y="286" width="375" height="66"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="VZv-L6-qF4" id="Gik-AE-HKx">
<frame key="frameInset" width="375" height="65"/>
<frame key="frameInset" width="375" height="66"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Имя" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="7ln-lu-1v3">
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Name" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="7ln-lu-1v3">
<constraints>
<constraint firstAttribute="width" constant="160" id="9sD-9A-VbA"/>
</constraints>
@@ -162,10 +162,17 @@
<rect key="frame" x="0.0" y="352" width="375" height="66"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="Nac-u5-yO4" id="58S-q5-nII">
<frame key="frameInset" width="375" height="65"/>
<frame key="frameInset" width="375" height="66"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Номер" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="IVt-iI-hFA">
<textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" textAlignment="right" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="dmg-Io-1BO" customClass="PassportTextField" customModule="DocumentsOCR_Example" customModuleProvider="target">
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<textInputTraits key="textInputTraits" autocapitalizationType="allCharacters" autocorrectionType="no" spellCheckingType="no"/>
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="string" keyPath="editTypeValue" value="None"/>
</userDefinedRuntimeAttributes>
</textField>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Passport number" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="IVt-iI-hFA">
<constraints>
<constraint firstAttribute="width" constant="160" id="nd2-q7-2z7"/>
</constraints>
@@ -179,13 +186,6 @@
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<textInputTraits key="textInputTraits"/>
</textField>
<textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" textAlignment="right" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="dmg-Io-1BO" customClass="PassportTextField" customModule="DocumentsOCR_Example" customModuleProvider="target">
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<textInputTraits key="textInputTraits" autocapitalizationType="allCharacters" autocorrectionType="no" spellCheckingType="no"/>
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="string" keyPath="editTypeValue" value="None"/>
</userDefinedRuntimeAttributes>
</textField>
</subviews>
<constraints>
<constraint firstItem="IVt-iI-hFA" firstAttribute="top" secondItem="58S-q5-nII" secondAttribute="topMargin" id="0tK-f6-ubG"/>
@@ -207,7 +207,7 @@
<rect key="frame" x="0.0" y="418" width="375" height="66"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="vdP-7h-8K3" id="Ki1-Q9-VMT">
<frame key="frameInset" width="375" height="65"/>
<frame key="frameInset" width="375" height="66"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" textAlignment="right" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="3dC-1U-poO" customClass="PassportTextField" customModule="DocumentsOCR_Example" customModuleProvider="target">
@@ -217,7 +217,7 @@
<userDefinedRuntimeAttribute type="string" keyPath="editTypeValue" value="Country"/>
</userDefinedRuntimeAttributes>
</textField>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Национальность" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="77b-iX-RR6">
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Nationality" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="77b-iX-RR6">
<constraints>
<constraint firstAttribute="width" constant="160" id="DI8-94-NIR"/>
</constraints>
@@ -252,7 +252,7 @@
<rect key="frame" x="0.0" y="484" width="375" height="66"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="nWJ-6j-2gn" id="gXi-lM-jGV">
<frame key="frameInset" width="375" height="65"/>
<frame key="frameInset" width="375" height="66"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" textAlignment="right" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="0KI-Lv-x3e" customClass="PassportTextField" customModule="DocumentsOCR_Example" customModuleProvider="target">
@@ -262,7 +262,7 @@
<userDefinedRuntimeAttribute type="string" keyPath="editTypeValue" value="Date"/>
</userDefinedRuntimeAttributes>
</textField>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Дата рождения" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="qOX-us-M0k">
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Day of birth" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="qOX-us-M0k">
<constraints>
<constraint firstAttribute="width" constant="160" id="Q08-r7-c62"/>
</constraints>
@@ -297,10 +297,10 @@
<rect key="frame" x="0.0" y="550" width="375" height="66"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="NZ6-gq-KyE" id="ep4-dI-S5o">
<frame key="frameInset" width="375" height="65"/>
<frame key="frameInset" width="375" height="66"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Пол" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="H0A-4b-jQn">
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Gender" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="H0A-4b-jQn">
<constraints>
<constraint firstAttribute="width" constant="160" id="vPs-du-LSm"/>
</constraints>
@@ -342,7 +342,7 @@
<rect key="frame" x="0.0" y="616" width="375" height="66"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="5Cw-cg-xba" id="HJ9-af-ld2">
<frame key="frameInset" width="375" height="65"/>
<frame key="frameInset" width="375" height="66"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" textAlignment="right" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="X5z-SK-Qne" customClass="PassportTextField" customModule="DocumentsOCR_Example" customModuleProvider="target">
@@ -352,7 +352,7 @@
<userDefinedRuntimeAttribute type="string" keyPath="editTypeValue" value="Date"/>
</userDefinedRuntimeAttributes>
</textField>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Окончание срока действия" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="dGu-jc-h7R">
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Expiring date" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="dGu-jc-h7R">
<constraints>
<constraint firstAttribute="width" constant="225" id="Mt4-b6-j4e"/>
</constraints>
@@ -387,7 +387,7 @@
<rect key="frame" x="0.0" y="682" width="375" height="66"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="EKR-ZQ-Hie" id="PQE-Sd-PhW">
<frame key="frameInset" width="375" height="65"/>
<frame key="frameInset" width="375" height="66"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" textAlignment="right" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="4IY-BG-79K" customClass="PassportTextField" customModule="DocumentsOCR_Example" customModuleProvider="target">
@@ -397,7 +397,7 @@
<userDefinedRuntimeAttribute type="string" keyPath="editTypeValue" value="Date"/>
</userDefinedRuntimeAttributes>
</textField>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Персональный номер" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="BjQ-Vu-JjL">
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Personal number" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="BjQ-Vu-JjL">
<constraints>
<constraint firstAttribute="width" constant="225" id="MTJ-hA-AkR"/>
</constraints>
+13 -10
View File
@@ -8,22 +8,25 @@
import Foundation
let simpleFormatter: NSDateFormatter = {
let formatter = NSDateFormatter()
let simpleFormatter: DateFormatter = {
let formatter = DateFormatter()
formatter.dateFormat = "yyyy-MM-dd"
formatter.timeZone = TimeZone(secondsFromGMT: 0)
return formatter
}()
extension NSDate {
static func dateFromPassportDateCode(code: String) -> NSDate? {
let year = code[0...3]
let month = code[4...5]
let day = code[6...7]
extension Date {
static func dateFromPassportDateCode(_ code: String) -> Date? {
return simpleFormatter.dateFromString("\(year)-\(month)-\(day)")
let year = code.substring(from: 0, to: 3)
let month = code.substring(from: 4, to: 5)
let day = code.substring(from: 6, to: 7)
return simpleFormatter.date(from: "\(year)-\(month)-\(day)")
}
var stringDate: String {
return simpleFormatter.stringFromDate(self)
return simpleFormatter.string(from: self)
}
}
}
+8 -8
View File
@@ -9,22 +9,22 @@
import UIKit
enum TextFieldType {
case Name, Date, Text, Sex, Country, None
case name, date, text, sex, country, none
}
class PassportTextField: UITextField {
var editType: TextFieldType {
set {
editTypeValue = String(newValue)
editTypeValue = String(describing: newValue)
}
get {
switch editTypeValue {
case "Name": return .Name
case "Date": return .Date
case "Text": return .Text
case "Sex": return .Sex
case "Country": return .Country
default: return .None
case "Name": return .name
case "Date": return .date
case "Text": return .text
case "Sex": return .sex
case "Country": return .country
default: return .none
}
}
}
@@ -9,6 +9,7 @@
import UIKit
import Darwin
import DocumentsOCR
import SVProgressHUD
class PassportViewController: UITableViewController {
@@ -28,7 +29,7 @@ class PassportViewController: UITableViewController {
@IBOutlet weak var cameraImageView: UIImageView!
let countries = Utils.stringFromTxtFile("CountryCodes")!.componentsSeparatedByString("\n")
let countries = Utils.stringFromTxtFile("CountryCodes")!.components(separatedBy: "\n")
func dismissKeyboard() {
self.view.endEditing(true)
@@ -37,7 +38,7 @@ class PassportViewController: UITableViewController {
override func viewDidLoad() {
super.viewDidLoad()
let paths = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true).first! as NSString
let paths = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true).first! as NSString
NSLog("\(paths)")
scanner = DocumentScanner(containerVC: self, withDelegate: self)
@@ -45,7 +46,7 @@ class PassportViewController: UITableViewController {
let tapGesture = UITapGestureRecognizer(target: self, action: #selector(self.dismissKeyboard))
self.view.addGestureRecognizer(tapGesture)
self.cameraImageView.contentMode = .ScaleAspectFit
self.cameraImageView.contentMode = .scaleAspectFit
// Set up country fields:
@@ -65,8 +66,8 @@ class PassportViewController: UITableViewController {
// Set up date fields:
let datePicker = UIDatePicker()
datePicker.addTarget(self, action: #selector(PassportViewController.datePickerValueChanged(_:)), forControlEvents: .ValueChanged)
datePicker.datePickerMode = UIDatePickerMode.Date
datePicker.addTarget(self, action: #selector(PassportViewController.datePickerValueChanged(_:)), for: .valueChanged)
datePicker.datePickerMode = UIDatePickerMode.date
dobField.delegate = self
expiredDateField.delegate = self
@@ -75,26 +76,31 @@ class PassportViewController: UITableViewController {
expiredDateField.inputView = datePicker
}
func datePickerValueChanged(sender: UIDatePicker) {
func datePickerValueChanged(_ sender: UIDatePicker) {
selectedTextField.text = sender.date.stringDate
}
@IBAction func cameraClicked(sender: UIBarButtonItem) {
@IBAction func cameraClicked(_ sender: UIBarButtonItem) {
scanner.presentCameraViewController()
}
override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
return .Portrait
override var supportedInterfaceOrientations : UIInterfaceOrientationMask {
return .portrait
}
}
extension PassportViewController: DocumentScannerDelegate {
func documentScanner(scanner: DocumentScanner, willBeginScanningImage image: UIImage) {
self.cameraImageView.image = image
func documentScanner(_ scanner: DocumentScanner, willBeginScanningImages images: [UIImage]) {
self.cameraImageView.image = images.first!
SVProgressHUD.showProgress(0, status: "Scanning")
}
func documentScanner(scanner: DocumentScanner, didFinishScanningWithInfo info: DocumentInfo) {
func documentScanner(_ scanner: DocumentScanner, recognitionProgress progress: Double) {
SVProgressHUD.showProgress(Float(progress), status: "Scanning")
}
func documentScanner(_ scanner: DocumentScanner, didFinishScanningWithInfo info: DocumentInfo) {
NSLog("Info: \(info)")
countryField.text = info.issuingCountryCode
@@ -107,9 +113,9 @@ extension PassportViewController: DocumentScannerDelegate {
let sex: String = {
switch info.gender {
case .Female:
case .female:
return "Женщина"
case .Male:
case .male:
return "Мужчина"
default:
return "?"
@@ -118,18 +124,20 @@ extension PassportViewController: DocumentScannerDelegate {
sexField.text = sex
expiredDateField.text = info.expirationDate?.stringDate
personalNumberField.text = info.personalNumber
SVProgressHUD.dismiss()
}
func documentScanner(scanner: DocumentScanner, didFailWithError error: NSError) {
func documentScanner(_ scanner: DocumentScanner, didFailWithError error: NSError) {
NSLog("Ошибка \(error.localizedDescription)")
SVProgressHUD.dismiss()
self.showErrorAlert(withMessage: error.localizedDescription)
}
}
extension PassportViewController: UITextFieldDelegate {
func textFieldShouldBeginEditing(textField: UITextField) -> Bool {
func textFieldShouldBeginEditing(_ textField: UITextField) -> Bool {
guard let passportField = textField as? PassportTextField else {
NSLog("Ошибка: неверный тип текстового поля")
return true
@@ -143,20 +151,20 @@ extension PassportViewController: UITextFieldDelegate {
extension PassportViewController: UIPickerViewDelegate, UIPickerViewDataSource {
func numberOfComponentsInPickerView(pickerView: UIPickerView) -> Int {
func numberOfComponents(in pickerView: UIPickerView) -> Int {
return 1
}
func pickerView(pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
return countries.count
}
func pickerView(pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
return countries[row]
}
func pickerView(pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
selectedTextField?.text = countries[row][0...2]
func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
selectedTextField?.text = countries[row].substring(from: 0, to: 2)
}
}
+7 -10
View File
@@ -3,16 +3,13 @@ import Foundation
extension String {
subscript (i: Int) -> Character {
return self[self.startIndex.advancedBy(i)]
let index = self.index(self.startIndex, offsetBy: i)
return self.characters[index]
}
subscript (i: Int) -> String {
return String(self[i] as Character)
func substring(from: Int, to: Int) -> String {
let fromIndex = self.index(self.startIndex, offsetBy: from)
let toIndex = self.index(self.startIndex, offsetBy: to + 1)
return self.substring(with: fromIndex ..< toIndex)
}
subscript (r: Range<Int>) -> String {
let start = startIndex.advancedBy(r.startIndex)
let end = start.advancedBy(r.endIndex - r.startIndex)
return self[Range(start ..< end)]
}
}
}
@@ -11,10 +11,10 @@ import UIKit
extension UIViewController {
func showErrorAlert(withMessage message: String) {
let alertVC = UIAlertController(title: "Ошибка", message: message, preferredStyle: .Alert)
let okAction = UIAlertAction(title: "OK", style: .Default, handler: nil)
let alertVC = UIAlertController(title: "Ошибка", message: message, preferredStyle: .alert)
let okAction = UIAlertAction(title: "OK", style: .default, handler: nil)
alertVC.addAction(okAction)
presentViewController(alertVC, animated: true, completion: nil)
present(alertVC, animated: true, completion: nil)
}
}
}
+1
View File
@@ -2,6 +2,7 @@ use_frameworks!
target 'DocumentsOCR_Example' do
pod 'DocumentsOCR', :path => '../'
pod 'SVProgressHUD'
target 'DocumentsOCR_Tests' do
inherit! :search_paths
+6 -3
View File
@@ -1,25 +1,28 @@
PODS:
- DocumentsOCR (0.5.2):
- DocumentsOCR (0.7.0):
- GPUImage
- PodAsset
- TesseractOCRiOS (~> 4.0.0)
- GPUImage (0.1.7)
- PodAsset (0.12.0)
- SVProgressHUD (2.0.3)
- TesseractOCRiOS (4.0.0)
DEPENDENCIES:
- DocumentsOCR (from `../`)
- SVProgressHUD
EXTERNAL SOURCES:
DocumentsOCR:
:path: ../
SPEC CHECKSUMS:
DocumentsOCR: 3e889ae553da6d94dbab58248bc30b0895437b94
DocumentsOCR: 57941b9ea95831ce389a75c2871e998ada07dae2
GPUImage: 733a5f0fab92df9de1c37ba9df520a833ccb406d
PodAsset: d6e724524e63725ef0c579354819ccc2dcbcf920
SVProgressHUD: b0830714205bea1317ea1a2ebc71e5633af334d4
TesseractOCRiOS: 90638afbe43d082433f2e76b384c7901d23956df
PODFILE CHECKSUM: 907e31037f951272b80e3591d4540e04d3e3fa69
PODFILE CHECKSUM: cd9f61bbc718914f9f971ce0f0248a7f58e7038b
COCOAPODS: 1.1.0.rc.2
+4 -4
View File
@@ -1,8 +1,8 @@
{
"name": "DocumentsOCR",
"version": "0.5.2",
"version": "0.7.0",
"summary": "A Swift framework for machine readable documents recognition",
"homepage": "https://github.com/appintheair/passport-ocr-ios",
"homepage": "https://github.com/appintheair/documents-ocr-ios",
"license": {
"type": "MIT",
"file": "LICENSE"
@@ -11,8 +11,8 @@
"Michael": "mmbabaev@gmail.com"
},
"source": {
"git": "https://github.com/appintheair/passport-ocr-ios.git",
"tag": "0.5.2"
"git": "https://github.com/appintheair/documents-ocr-ios",
"tag": "0.7.0"
},
"platforms": {
"ios": "8.0"
+6 -3
View File
@@ -1,25 +1,28 @@
PODS:
- DocumentsOCR (0.5.2):
- DocumentsOCR (0.7.0):
- GPUImage
- PodAsset
- TesseractOCRiOS (~> 4.0.0)
- GPUImage (0.1.7)
- PodAsset (0.12.0)
- SVProgressHUD (2.0.3)
- TesseractOCRiOS (4.0.0)
DEPENDENCIES:
- DocumentsOCR (from `../`)
- SVProgressHUD
EXTERNAL SOURCES:
DocumentsOCR:
:path: ../
SPEC CHECKSUMS:
DocumentsOCR: 3e889ae553da6d94dbab58248bc30b0895437b94
DocumentsOCR: 57941b9ea95831ce389a75c2871e998ada07dae2
GPUImage: 733a5f0fab92df9de1c37ba9df520a833ccb406d
PodAsset: d6e724524e63725ef0c579354819ccc2dcbcf920
SVProgressHUD: b0830714205bea1317ea1a2ebc71e5633af334d4
TesseractOCRiOS: 90638afbe43d082433f2e76b384c7901d23956df
PODFILE CHECKSUM: 907e31037f951272b80e3591d4540e04d3e3fa69
PODFILE CHECKSUM: cd9f61bbc718914f9f971ce0f0248a7f58e7038b
COCOAPODS: 1.1.0.rc.2
+3616 -3395
View File
File diff suppressed because it is too large Load Diff
+26
View File
@@ -0,0 +1,26 @@
Copyright (c) 2011-2016 Sam Vermette, Tobias Tiemerding and contributors.
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
A different license may apply to other resources included in this package,
including Freepik Icons. Please consult their
respective headers for the terms of their individual licenses.
+196
View File
@@ -0,0 +1,196 @@
# SVProgressHUD
![Pod Version](https://img.shields.io/cocoapods/v/SVProgressHUD.svg?style=flat)
![Pod License](https://img.shields.io/cocoapods/l/SVProgressHUD.svg?style=flat)
![Pod Platform](https://img.shields.io/cocoapods/p/SVProgressHUD.svg?style=flat)
[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)
`SVProgressHUD` is a clean and easy-to-use HUD meant to display the progress of an ongoing task on iOS and tvOS.
![SVProgressHUD](http://f.cl.ly/items/2G1F1Z0M0k0h2U3V1p39/SVProgressHUD.gif)
## Demo
Try `SVProgressHUD` on [Appetize.io](https://appetize.io/app/p8r2cvy8kq74x7q7tjqf5gyatr).
## Installation
### From CocoaPods
[CocoaPods](http://cocoapods.org) is a dependency manager for Objective-C, which automates and simplifies the process of using 3rd-party libraries like `SVProgressHUD` in your projects. First, add the following line to your [Podfile](http://guides.cocoapods.org/using/using-cocoapods.html):
```ruby
pod 'SVProgressHUD'
```
If you want to use the latest features of `SVProgressHUD` use normal external source dependencies.
```ruby
pod 'SVProgressHUD', :git => 'https://github.com/SVProgressHUD/SVProgressHUD.git'
```
This pulls from the `master` branch directly. We are usually careful about what we push there and this is the version we use ourselves in all of our projects.
Second, install `SVProgressHUD` into your project:
```ruby
pod install
```
### Carthage
[Carthage](https://github.com/Carthage/Carthage) is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.
You can install Carthage with [Homebrew](http://brew.sh/) using the following command:
```bash
$ brew update
$ brew install carthage
```
To integrate `SVProgressHUD` into your Xcode project using Carthage, specify it in your `Cartfile`:
```ogdl
github "SVProgressHUD/SVProgressHUD"
```
Run `carthage update` to build the framework and drag the built `SVProgressHUD.framework` (in Carthage/Build/iOS folder) into your Xcode project (Linked Frameworks and Libraries in `Targets`).
### Manually
* Drag the `SVProgressHUD/SVProgressHUD` folder into your project.
* Take care that `SVProgressHUD.bundle` is added to `Targets->Build Phases->Copy Bundle Resources`.
* Add the **QuartzCore** framework to your project.
## Usage
(see sample Xcode project in `/Demo`)
`SVProgressHUD` is created as a singleton (i.e. it doesn't need to be explicitly allocated and instantiated; you directly call `[SVProgressHUD method]`).
**Use `SVProgressHUD` wisely! Only use it if you absolutely need to perform a task before taking the user forward. Bad use case examples: pull to refresh, infinite scrolling, sending message.**
Using `SVProgressHUD` in your app will usually look as simple as this (using Grand Central Dispatch):
```objective-c
[SVProgressHUD show];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
// time-consuming task
dispatch_async(dispatch_get_main_queue(), ^{
[SVProgressHUD dismiss];
});
});
```
### Showing the HUD
You can show the status of indeterminate tasks using one of the following:
```objective-c
+ (void)show;
+ (void)showWithStatus:(NSString*)string;
```
If you'd like the HUD to reflect the progress of a task, use one of these:
```objective-c
+ (void)showProgress:(CGFloat)progress;
+ (void)showProgress:(CGFloat)progress status:(NSString*)status;
```
### Dismissing the HUD
The HUD can be dismissed using:
```objective-c
+ (void)dismiss;
+ (void)dismissWithDelay:(NSTimeInterval)delay;
```
If you'd like to stack HUDs, you can balance out every show call using:
```objective-c
+ (void)popActivity;
```
The HUD will get dismissed once the `popActivity` calls will match the number of show calls.
Or show a confirmation glyph before before getting dismissed a little bit later. The display time depends on `minimumDismissTimeInterval` and the length of the given string.
```objective-c
+ (void)showInfoWithStatus:(NSString*)string;
+ (void)showSuccessWithStatus:(NSString*)string;
+ (void)showErrorWithStatus:(NSString*)string;
+ (void)showImage:(UIImage*)image status:(NSString*)string;
```
## Customization
`SVProgressHUD` can be customized via the following methods:
```objective-c
+ (void)setDefaultStyle:(SVProgressHUDStyle)style; // default is SVProgressHUDStyleLight
+ (void)setDefaultMaskType:(SVProgressHUDMaskType)maskType; // default is SVProgressHUDMaskTypeNone
+ (void)setDefaultAnimationType:(SVProgressHUDAnimationType)type; // default is SVProgressHUDAnimationTypeFlat
+ (void)setMinimumSize:(CGSize)minimumSize; // default is CGSizeZero, can be used to avoid resizing for a larger message
+ (void)setRingThickness:(CGFloat)width; // default is 2 pt
+ (void)setRingRadius:(CGFloat)radius; // default is 18 pt
+ (void)setRingNoTextRadius:(CGFloat)radius; // default is 24 pt
+ (void)setCornerRadius:(CGFloat)cornerRadius; // default is 14 pt
+ (void)setFont:(UIFont*)font; // default is [UIFont preferredFontForTextStyle:UIFontTextStyleSubheadline]
+ (void)setForegroundColor:(UIColor*)color; // default is [UIColor blackColor], only used for SVProgressHUDStyleCustom
+ (void)setBackgroundColor:(UIColor*)color; // default is [UIColor whiteColor], only used for SVProgressHUDStyleCustom
+ (void)setBackgroundLayerColor:(UIColor*)color; // default is [UIColor colorWithWhite:0 alpha:0.4], only used for SVProgressHUDMaskTypeCustom
+ (void)setInfoImage:(UIImage*)image; // default is the bundled info image provided by Freepik
+ (void)setSuccessImage:(UIImage*)image; // default is bundled success image from Freepik
+ (void)setErrorImage:(UIImage*)image; // default is bundled error image from Freepik
+ (void)setViewForExtension:(UIView*)view; // default is nil, only used if #define SV_APP_EXTENSIONS is set
+ (void)setMinimumDismissTimeInterval:(NSTimeInterval)interval; // default is 5.0 seconds
+ (void)setFadeInAnimationDuration:(NSTimeInterval)duration; // default is 0.15 seconds
+ (void)setFadeOutAnimationDuration:(NSTimeInterval)duration; // default is 0.15 seconds
```
Additionally `SVProgressHUD` supports the `UIAppearance` protocol for most of the above methods.
### Hint
As standard `SVProgressHUD` offers two preconfigured styles:
* `SVProgressHUDStyleLight`: White background with black spinner and text
* `SVProgressHUDStyleDark`: Black background with white spinner and text
If you want to use custom colors with `setForegroundColor` and `setBackgroundColor:` don't forget to set `SVProgressHUDStyleCustom` via `setDefaultStyle:`.
## Notifications
`SVProgressHUD` posts four notifications via `NSNotificationCenter` in response to being shown/dismissed:
* `SVProgressHUDWillAppearNotification` when the show animation starts
* `SVProgressHUDDidAppearNotification` when the show animation completes
* `SVProgressHUDWillDisappearNotification` when the dismiss animation starts
* `SVProgressHUDDidDisappearNotification` when the dismiss animation completes
Each notification passes a `userInfo` dictionary holding the HUD's status string (if any), retrievable via `SVProgressHUDStatusUserInfoKey`.
`SVProgressHUD` also posts `SVProgressHUDDidReceiveTouchEventNotification` when users touch on the overall screen or `SVProgressHUDDidTouchDownInsideNotification` when a user touches on the HUD directly. For this notifications `userInfo` is not passed but the object parameter contains the `UIEvent` that related to the touch.
## App Extensions
When using `SVProgressHUD` in an App Extension, `#define SV_APP_EXTENSIONS` to avoid using unavailable APIs. Additionally call `setViewForExtension:` from your extensions view controller with `self.view`.
## Contributing to this project
If you have feature requests or bug reports, feel free to help out by sending pull requests or by [creating new issues](https://github.com/SVProgressHUD/SVProgressHUD/issues/new). Please take a moment to
review the guidelines written by [Nicolas Gallagher](https://github.com/necolas):
* [Bug reports](https://github.com/necolas/issue-guidelines/blob/master/CONTRIBUTING.md#bugs)
* [Feature requests](https://github.com/necolas/issue-guidelines/blob/master/CONTRIBUTING.md#features)
* [Pull requests](https://github.com/necolas/issue-guidelines/blob/master/CONTRIBUTING.md#pull-requests)
## License
`SVProgressHUD` is distributed under the terms and conditions of the [MIT license](https://github.com/SVProgressHUD/SVProgressHUD/blob/master/LICENSE.txt). The success, error and info icons are made by [Freepik](http://www.freepik.com) from [Flaticon](http://www.flaticon.com) and are licensed under [Creative Commons BY 3.0](http://creativecommons.org/licenses/by/3.0/).
## Credits
`SVProgressHUD` is brought to you by [Sam Vermette](http://samvermette.com), [Tobias Tiemerding](http://tiemerding.com) and [contributors to the project](https://github.com/SVProgressHUD/SVProgressHUD/contributors). If you're using `SVProgressHUD` in your project, attribution would be very appreciated.
@@ -0,0 +1,17 @@
//
// SVIndefiniteAnimatedView.h
// SVProgressHUD, https://github.com/SVProgressHUD/SVProgressHUD
//
// Copyright (c) 2014-2016 Guillaume Campagna. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface SVIndefiniteAnimatedView : UIView
@property (nonatomic, assign) CGFloat strokeThickness;
@property (nonatomic, assign) CGFloat radius;
@property (nonatomic, strong) UIColor *strokeColor;
@end
@@ -0,0 +1,137 @@
//
// SVIndefiniteAnimatedView.m
// SVProgressHUD, https://github.com/SVProgressHUD/SVProgressHUD
//
// Copyright (c) 2014-2016 Guillaume Campagna. All rights reserved.
//
#import "SVIndefiniteAnimatedView.h"
#import "SVProgressHUD.h"
@interface SVIndefiniteAnimatedView ()
@property (nonatomic, strong) CAShapeLayer *indefiniteAnimatedLayer;
@end
@implementation SVIndefiniteAnimatedView
- (void)willMoveToSuperview:(UIView*)newSuperview {
if (newSuperview) {
[self layoutAnimatedLayer];
} else {
[_indefiniteAnimatedLayer removeFromSuperlayer];
_indefiniteAnimatedLayer = nil;
}
}
- (void)layoutAnimatedLayer {
CALayer *layer = self.indefiniteAnimatedLayer;
[self.layer addSublayer:layer];
CGFloat widthDiff = CGRectGetWidth(self.bounds) - CGRectGetWidth(layer.bounds);
CGFloat heightDiff = CGRectGetHeight(self.bounds) - CGRectGetHeight(layer.bounds);
layer.position = CGPointMake(CGRectGetWidth(self.bounds) - CGRectGetWidth(layer.bounds) / 2 - widthDiff / 2, CGRectGetHeight(self.bounds) - CGRectGetHeight(layer.bounds) / 2 - heightDiff / 2);
}
- (CAShapeLayer*)indefiniteAnimatedLayer {
if(!_indefiniteAnimatedLayer) {
CGPoint arcCenter = CGPointMake(self.radius+self.strokeThickness/2+5, self.radius+self.strokeThickness/2+5);
UIBezierPath* smoothedPath = [UIBezierPath bezierPathWithArcCenter:arcCenter radius:self.radius startAngle:(CGFloat) (M_PI*3/2) endAngle:(CGFloat) (M_PI/2+M_PI*5) clockwise:YES];
_indefiniteAnimatedLayer = [CAShapeLayer layer];
_indefiniteAnimatedLayer.contentsScale = [[UIScreen mainScreen] scale];
_indefiniteAnimatedLayer.frame = CGRectMake(0.0f, 0.0f, arcCenter.x*2, arcCenter.y*2);
_indefiniteAnimatedLayer.fillColor = [UIColor clearColor].CGColor;
_indefiniteAnimatedLayer.strokeColor = self.strokeColor.CGColor;
_indefiniteAnimatedLayer.lineWidth = self.strokeThickness;
_indefiniteAnimatedLayer.lineCap = kCALineCapRound;
_indefiniteAnimatedLayer.lineJoin = kCALineJoinBevel;
_indefiniteAnimatedLayer.path = smoothedPath.CGPath;
CALayer *maskLayer = [CALayer layer];
NSBundle *bundle = [NSBundle bundleForClass:[SVProgressHUD class]];
NSURL *url = [bundle URLForResource:@"SVProgressHUD" withExtension:@"bundle"];
NSBundle *imageBundle = [NSBundle bundleWithURL:url];
NSString *path = [imageBundle pathForResource:@"angle-mask" ofType:@"png"];
maskLayer.contents = (__bridge id)[[UIImage imageWithContentsOfFile:path] CGImage];
maskLayer.frame = _indefiniteAnimatedLayer.bounds;
_indefiniteAnimatedLayer.mask = maskLayer;
NSTimeInterval animationDuration = 1;
CAMediaTimingFunction *linearCurve = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
animation.fromValue = (id) 0;
animation.toValue = @(M_PI*2);
animation.duration = animationDuration;
animation.timingFunction = linearCurve;
animation.removedOnCompletion = NO;
animation.repeatCount = INFINITY;
animation.fillMode = kCAFillModeForwards;
animation.autoreverses = NO;
[_indefiniteAnimatedLayer.mask addAnimation:animation forKey:@"rotate"];
CAAnimationGroup *animationGroup = [CAAnimationGroup animation];
animationGroup.duration = animationDuration;
animationGroup.repeatCount = INFINITY;
animationGroup.removedOnCompletion = NO;
animationGroup.timingFunction = linearCurve;
CABasicAnimation *strokeStartAnimation = [CABasicAnimation animationWithKeyPath:@"strokeStart"];
strokeStartAnimation.fromValue = @0.015;
strokeStartAnimation.toValue = @0.515;
CABasicAnimation *strokeEndAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
strokeEndAnimation.fromValue = @0.485;
strokeEndAnimation.toValue = @0.985;
animationGroup.animations = @[strokeStartAnimation, strokeEndAnimation];
[_indefiniteAnimatedLayer addAnimation:animationGroup forKey:@"progress"];
}
return _indefiniteAnimatedLayer;
}
- (void)setFrame:(CGRect)frame {
if(!CGRectEqualToRect(frame, super.frame)) {
[super setFrame:frame];
if(self.superview) {
[self layoutAnimatedLayer];
}
}
}
- (void)setRadius:(CGFloat)radius {
if(radius != _radius) {
_radius = radius;
[_indefiniteAnimatedLayer removeFromSuperlayer];
_indefiniteAnimatedLayer = nil;
if(self.superview) {
[self layoutAnimatedLayer];
}
}
}
- (void)setStrokeColor:(UIColor*)strokeColor {
_strokeColor = strokeColor;
_indefiniteAnimatedLayer.strokeColor = strokeColor.CGColor;
}
- (void)setStrokeThickness:(CGFloat)strokeThickness {
_strokeThickness = strokeThickness;
_indefiniteAnimatedLayer.lineWidth = _strokeThickness;
}
- (CGSize)sizeThatFits:(CGSize)size {
return CGSizeMake((self.radius+self.strokeThickness/2+5)*2, (self.radius+self.strokeThickness/2+5)*2);
}
@end
@@ -0,0 +1,17 @@
//
// SVProgressAnimatedView.h
// SVProgressHUD, https://github.com/SVProgressHUD/SVProgressHUD
//
// Copyright (c) 2016 Tobias Tiemerding. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface SVProgressAnimatedView : UIView
@property (nonatomic, assign) CGFloat radius;
@property (nonatomic, assign) CGFloat strokeThickness;
@property (nonatomic, strong) UIColor *strokeColor;
@property (nonatomic, assign) CGFloat strokeEnd;
@end
@@ -0,0 +1,98 @@
//
// SVProgressAnimatedView.m
// SVProgressHUD, https://github.com/SVProgressHUD/SVProgressHUD
//
// Copyright (c) 2016 Tobias Tiemerding. All rights reserved.
//
#import "SVProgressAnimatedView.h"
@interface SVProgressAnimatedView ()
@property (nonatomic, strong) CAShapeLayer *ringAnimatedLayer;
@end
@implementation SVProgressAnimatedView
- (void)willMoveToSuperview:(UIView*)newSuperview {
if (newSuperview) {
[self layoutAnimatedLayer];
} else {
[_ringAnimatedLayer removeFromSuperlayer];
_ringAnimatedLayer = nil;
}
}
- (void)layoutAnimatedLayer {
CALayer *layer = self.ringAnimatedLayer;
[self.layer addSublayer:layer];
CGFloat widthDiff = CGRectGetWidth(self.bounds) - CGRectGetWidth(layer.bounds);
CGFloat heightDiff = CGRectGetHeight(self.bounds) - CGRectGetHeight(layer.bounds);
layer.position = CGPointMake(CGRectGetWidth(self.bounds) - CGRectGetWidth(layer.bounds) / 2 - widthDiff / 2, CGRectGetHeight(self.bounds) - CGRectGetHeight(layer.bounds) / 2 - heightDiff / 2);
}
- (CAShapeLayer*)ringAnimatedLayer {
if(!_ringAnimatedLayer) {
CGPoint arcCenter = CGPointMake(self.radius+self.strokeThickness/2+5, self.radius+self.strokeThickness/2+5);
UIBezierPath* smoothedPath = [UIBezierPath bezierPathWithArcCenter:arcCenter radius:self.radius startAngle:(CGFloat)-M_PI_2 endAngle:(CGFloat) (M_PI + M_PI_2) clockwise:YES];
_ringAnimatedLayer = [CAShapeLayer layer];
_ringAnimatedLayer.contentsScale = [[UIScreen mainScreen] scale];
_ringAnimatedLayer.frame = CGRectMake(0.0f, 0.0f, arcCenter.x*2, arcCenter.y*2);
_ringAnimatedLayer.fillColor = [UIColor clearColor].CGColor;
_ringAnimatedLayer.strokeColor = self.strokeColor.CGColor;
_ringAnimatedLayer.lineWidth = self.strokeThickness;
_ringAnimatedLayer.lineCap = kCALineCapRound;
_ringAnimatedLayer.lineJoin = kCALineJoinBevel;
_ringAnimatedLayer.path = smoothedPath.CGPath;
}
return _ringAnimatedLayer;
}
- (void)setFrame:(CGRect)frame {
if(!CGRectEqualToRect(frame, super.frame)) {
[super setFrame:frame];
if(self.superview) {
[self layoutAnimatedLayer];
}
}
}
- (void)setRadius:(CGFloat)radius {
if(radius != _radius) {
_radius = radius;
[_ringAnimatedLayer removeFromSuperlayer];
_ringAnimatedLayer = nil;
if(self.superview) {
[self layoutAnimatedLayer];
}
}
}
- (void)setStrokeColor:(UIColor*)strokeColor {
_strokeColor = strokeColor;
_ringAnimatedLayer.strokeColor = strokeColor.CGColor;
}
- (void)setStrokeThickness:(CGFloat)strokeThickness {
_strokeThickness = strokeThickness;
_ringAnimatedLayer.lineWidth = _strokeThickness;
}
- (void)setStrokeEnd:(CGFloat)strokeEnd {
_strokeEnd = strokeEnd;
_ringAnimatedLayer.strokeEnd = _strokeEnd;
}
- (CGSize)sizeThatFits:(CGSize)size {
return CGSizeMake((self.radius+self.strokeThickness/2+5)*2, (self.radius+self.strokeThickness/2+5)*2);
}
@end
Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 184 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 306 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 398 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 365 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 816 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 262 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 462 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 714 B

+131
View File
@@ -0,0 +1,131 @@
//
// SVProgressHUD.h
// SVProgressHUD, https://github.com/SVProgressHUD/SVProgressHUD
//
// Copyright (c) 2011-2016 Sam Vermette and contributors. All rights reserved.
//
#import <UIKit/UIKit.h>
#import <AvailabilityMacros.h>
#if __IPHONE_OS_VERSION_MAX_ALLOWED < 70000
#define UI_APPEARANCE_SELECTOR
#endif
extern NSString * const SVProgressHUDDidReceiveTouchEventNotification;
extern NSString * const SVProgressHUDDidTouchDownInsideNotification;
extern NSString * const SVProgressHUDWillDisappearNotification;
extern NSString * const SVProgressHUDDidDisappearNotification;
extern NSString * const SVProgressHUDWillAppearNotification;
extern NSString * const SVProgressHUDDidAppearNotification;
extern NSString * const SVProgressHUDStatusUserInfoKey;
typedef NS_ENUM(NSInteger, SVProgressHUDStyle) {
SVProgressHUDStyleLight, // default style, white HUD with black text, HUD background will be blurred on iOS 8 and above
SVProgressHUDStyleDark, // black HUD and white text, HUD background will be blurred on iOS 8 and above
SVProgressHUDStyleCustom // uses the fore- and background color properties
};
typedef NS_ENUM(NSUInteger, SVProgressHUDMaskType) {
SVProgressHUDMaskTypeNone = 1, // default mask type, allow user interactions while HUD is displayed
SVProgressHUDMaskTypeClear, // don't allow user interactions
SVProgressHUDMaskTypeBlack, // don't allow user interactions and dim the UI in the back of the HUD, as on iOS 7 and above
SVProgressHUDMaskTypeGradient, // don't allow user interactions and dim the UI with a a-la UIAlertView background gradient, as on iOS 6
SVProgressHUDMaskTypeCustom // don't allow user interactions and dim the UI in the back of the HUD with a custom color
};
typedef NS_ENUM(NSUInteger, SVProgressHUDAnimationType) {
SVProgressHUDAnimationTypeFlat, // default animation type, custom flat animation (indefinite animated ring)
SVProgressHUDAnimationTypeNative // iOS native UIActivityIndicatorView
};
@interface SVProgressHUD : UIView
#pragma mark - Customization
@property (assign, nonatomic) SVProgressHUDStyle defaultStyle UI_APPEARANCE_SELECTOR; // default is SVProgressHUDStyleLight
@property (assign, nonatomic) SVProgressHUDMaskType defaultMaskType UI_APPEARANCE_SELECTOR; // default is SVProgressHUDMaskTypeNone
@property (assign, nonatomic) SVProgressHUDAnimationType defaultAnimationType UI_APPEARANCE_SELECTOR; // default is SVProgressHUDAnimationTypeFlat
@property (assign, nonatomic) CGSize minimumSize UI_APPEARANCE_SELECTOR; // default is CGSizeZero, can be used to avoid resizing for a larger message
@property (assign, nonatomic) CGFloat ringThickness UI_APPEARANCE_SELECTOR; // default is 2 pt
@property (assign, nonatomic) CGFloat ringRadius UI_APPEARANCE_SELECTOR; // default is 18 pt
@property (assign, nonatomic) CGFloat ringNoTextRadius UI_APPEARANCE_SELECTOR; // default is 24 pt
@property (assign, nonatomic) CGFloat cornerRadius UI_APPEARANCE_SELECTOR; // default is 14 pt
@property (strong, nonatomic) UIFont *font UI_APPEARANCE_SELECTOR; // default is [UIFont preferredFontForTextStyle:UIFontTextStyleSubheadline]
@property (strong, nonatomic) UIColor *backgroundColor UI_APPEARANCE_SELECTOR; // default is [UIColor whiteColor]
@property (strong, nonatomic) UIColor *foregroundColor UI_APPEARANCE_SELECTOR; // default is [UIColor blackColor]
@property (strong, nonatomic) UIColor *backgroundLayerColor UI_APPEARANCE_SELECTOR; // default is [UIColor colorWithWhite:0 alpha:0.4]
@property (strong, nonatomic) UIImage *infoImage UI_APPEARANCE_SELECTOR; // default is the bundled info image provided by Freepik
@property (strong, nonatomic) UIImage *successImage UI_APPEARANCE_SELECTOR; // default is the bundled success image provided by Freepik
@property (strong, nonatomic) UIImage *errorImage UI_APPEARANCE_SELECTOR; // default is the bundled error image provided by Freepik
@property (strong, nonatomic) UIView *viewForExtension UI_APPEARANCE_SELECTOR; // default is nil, only used if #define SV_APP_EXTENSIONS is set
@property (assign, nonatomic) NSTimeInterval minimumDismissTimeInterval; // default is 5.0 seconds
@property (assign, nonatomic) UIOffset offsetFromCenter UI_APPEARANCE_SELECTOR; // default is 0, 0
@property (assign, nonatomic) NSTimeInterval fadeInAnimationDuration; // default is 0.15
@property (assign, nonatomic) NSTimeInterval fadeOutAnimationDuration; // default is 0.15
+ (void)setDefaultStyle:(SVProgressHUDStyle)style; // default is SVProgressHUDStyleLight
+ (void)setDefaultMaskType:(SVProgressHUDMaskType)maskType; // default is SVProgressHUDMaskTypeNone
+ (void)setDefaultAnimationType:(SVProgressHUDAnimationType)type; // default is SVProgressHUDAnimationTypeFlat
+ (void)setMinimumSize:(CGSize)minimumSize; // default is CGSizeZero, can be used to avoid resizing for a larger message
+ (void)setRingThickness:(CGFloat)ringThickness; // default is 2 pt
+ (void)setRingRadius:(CGFloat)radius; // default is 18 pt
+ (void)setRingNoTextRadius:(CGFloat)radius; // default is 24 pt
+ (void)setCornerRadius:(CGFloat)cornerRadius; // default is 14 pt
+ (void)setFont:(UIFont*)font; // default is [UIFont preferredFontForTextStyle:UIFontTextStyleSubheadline]
+ (void)setForegroundColor:(UIColor*)color; // default is [UIColor blackColor], only used for SVProgressHUDStyleCustom
+ (void)setBackgroundColor:(UIColor*)color; // default is [UIColor whiteColor], only used for SVProgressHUDStyleCustom
+ (void)setBackgroundLayerColor:(UIColor*)color; // default is [UIColor colorWithWhite:0 alpha:0.5], only used for SVProgressHUDMaskTypeBlack
+ (void)setInfoImage:(UIImage*)image; // default is the bundled info image provided by Freepik
+ (void)setSuccessImage:(UIImage*)image; // default is the bundled success image provided by Freepik
+ (void)setErrorImage:(UIImage*)image; // default is the bundled error image provided by Freepik
+ (void)setViewForExtension:(UIView*)view; // default is nil, only used if #define SV_APP_EXTENSIONS is set
+ (void)setMinimumDismissTimeInterval:(NSTimeInterval)interval; // default is 5.0 seconds
+ (void)setFadeInAnimationDuration:(NSTimeInterval)duration; // default is 0.15 seconds
+ (void)setFadeOutAnimationDuration:(NSTimeInterval)duration; // default is 0.15 seconds
#pragma mark - Show Methods
+ (void)show;
+ (void)showWithMaskType:(SVProgressHUDMaskType)maskType __attribute__((deprecated("Use show and setDefaultMaskType: instead.")));
+ (void)showWithStatus:(NSString*)status;
+ (void)showWithStatus:(NSString*)status maskType:(SVProgressHUDMaskType)maskType __attribute__((deprecated("Use showWithStatus: and setDefaultMaskType: instead.")));
+ (void)showProgress:(float)progress;
+ (void)showProgress:(float)progress maskType:(SVProgressHUDMaskType)maskType __attribute__((deprecated("Use showProgress: and setDefaultMaskType: instead.")));
+ (void)showProgress:(float)progress status:(NSString*)status;
+ (void)showProgress:(float)progress status:(NSString*)status maskType:(SVProgressHUDMaskType)maskType __attribute__((deprecated("Use showProgress:status: and setDefaultMaskType: instead.")));
+ (void)setStatus:(NSString*)status; // change the HUD loading status while it's showing
// stops the activity indicator, shows a glyph + status, and dismisses the HUD a little bit later
+ (void)showInfoWithStatus:(NSString*)status;
+ (void)showInfoWithStatus:(NSString*)status maskType:(SVProgressHUDMaskType)maskType __attribute__((deprecated("Use showInfoWithStatus: and setDefaultMaskType: instead.")));
+ (void)showSuccessWithStatus:(NSString*)status;
+ (void)showSuccessWithStatus:(NSString*)status maskType:(SVProgressHUDMaskType)maskType __attribute__((deprecated("Use showSuccessWithStatus: and setDefaultMaskType: instead.")));
+ (void)showErrorWithStatus:(NSString*)status;
+ (void)showErrorWithStatus:(NSString*)status maskType:(SVProgressHUDMaskType)maskType __attribute__((deprecated("Use showErrorWithStatus: and setDefaultMaskType: instead.")));
// shows a image + status, use 28x28 white PNGs
+ (void)showImage:(UIImage*)image status:(NSString*)status;
+ (void)showImage:(UIImage*)image status:(NSString*)status maskType:(SVProgressHUDMaskType)maskType __attribute__((deprecated("Use showImage:status: and setDefaultMaskType: instead.")));
+ (void)setOffsetFromCenter:(UIOffset)offset;
+ (void)resetOffsetFromCenter;
+ (void)popActivity; // decrease activity count, if activity count == 0 the HUD is dismissed
+ (void)dismiss;
+ (void)dismissWithDelay:(NSTimeInterval)delay;
+ (BOOL)isVisible;
+ (NSTimeInterval)displayDurationForString:(NSString*)string;
@end
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,14 @@
//
// SVRadialGradientLayer.h
// SVProgressHUD, https://github.com/SVProgressHUD/SVProgressHUD
//
// Copyright (c) 2014-2016 Tobias Tiemerding. All rights reserved.
//
#import <QuartzCore/QuartzCore.h>
@interface SVRadialGradientLayer : CALayer
@property (nonatomic) CGPoint gradientCenter;
@end
@@ -0,0 +1,25 @@
//
// SVRadialGradientLayer.m
// SVProgressHUD, https://github.com/SVProgressHUD/SVProgressHUD
//
// Copyright (c) 2014-2016 Tobias Tiemerding. All rights reserved.
//
#import "SVRadialGradientLayer.h"
@implementation SVRadialGradientLayer
- (void)drawInContext:(CGContextRef)context {
size_t locationsCount = 2;
CGFloat locations[2] = {0.0f, 1.0f};
CGFloat colors[8] = {0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.75f};
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGGradientRef gradient = CGGradientCreateWithColorComponents(colorSpace, colors, locations, locationsCount);
CGColorSpaceRelease(colorSpace);
float radius = MIN(self.bounds.size.width , self.bounds.size.height);
CGContextDrawRadialGradient (context, gradient, self.gradientCenter, 0, self.gradientCenter, radius, kCGGradientDrawsAfterEndLocation);
CGGradientRelease(gradient);
}
@end
+1 -1
View File
@@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>0.5.2</string>
<string>0.7.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
@@ -13,7 +13,7 @@
<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleShortVersionString</key>
<string>0.5.2</string>
<string>0.7.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
@@ -60,6 +60,36 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
## SVProgressHUD
Copyright (c) 2011-2016 Sam Vermette, Tobias Tiemerding and contributors.
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
A different license may apply to other resources included in this package,
including Freepik Icons. Please consult their
respective headers for the terms of their individual licenses.
## TesseractOCRiOS
The MIT License (MIT)
@@ -89,6 +89,42 @@ THE SOFTWARE.
<key>Type</key>
<string>PSGroupSpecifier</string>
</dict>
<dict>
<key>FooterText</key>
<string>Copyright (c) 2011-2016 Sam Vermette, Tobias Tiemerding and contributors.
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
A different license may apply to other resources included in this package,
including Freepik Icons. Please consult their
respective headers for the terms of their individual licenses.
</string>
<key>License</key>
<string>MIT</string>
<key>Title</key>
<string>SVProgressHUD</string>
<key>Type</key>
<string>PSGroupSpecifier</string>
</dict>
<dict>
<key>FooterText</key>
<string>The MIT License (MIT)
@@ -87,11 +87,13 @@ if [[ "$CONFIGURATION" == "Debug" ]]; then
install_framework "$BUILT_PRODUCTS_DIR/DocumentsOCR/DocumentsOCR.framework"
install_framework "$BUILT_PRODUCTS_DIR/GPUImage/GPUImage.framework"
install_framework "$BUILT_PRODUCTS_DIR/PodAsset/PodAsset.framework"
install_framework "$BUILT_PRODUCTS_DIR/SVProgressHUD/SVProgressHUD.framework"
install_framework "$BUILT_PRODUCTS_DIR/TesseractOCRiOS/TesseractOCR.framework"
fi
if [[ "$CONFIGURATION" == "Release" ]]; then
install_framework "$BUILT_PRODUCTS_DIR/DocumentsOCR/DocumentsOCR.framework"
install_framework "$BUILT_PRODUCTS_DIR/GPUImage/GPUImage.framework"
install_framework "$BUILT_PRODUCTS_DIR/PodAsset/PodAsset.framework"
install_framework "$BUILT_PRODUCTS_DIR/SVProgressHUD/SVProgressHUD.framework"
install_framework "$BUILT_PRODUCTS_DIR/TesseractOCRiOS/TesseractOCR.framework"
fi
@@ -2,11 +2,11 @@ ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES
CLANG_CXX_LIBRARY = compiler-default
CLANG_MODULES_AUTOLINK = YES
EMBEDDED_CONTENT_CONTAINS_SWIFT = YES
FRAMEWORK_SEARCH_PATHS = $(inherited) "$PODS_CONFIGURATION_BUILD_DIR/DocumentsOCR" "$PODS_CONFIGURATION_BUILD_DIR/GPUImage" "$PODS_CONFIGURATION_BUILD_DIR/PodAsset" "$PODS_CONFIGURATION_BUILD_DIR/TesseractOCRiOS"
FRAMEWORK_SEARCH_PATHS = $(inherited) "$PODS_CONFIGURATION_BUILD_DIR/DocumentsOCR" "$PODS_CONFIGURATION_BUILD_DIR/GPUImage" "$PODS_CONFIGURATION_BUILD_DIR/PodAsset" "$PODS_CONFIGURATION_BUILD_DIR/SVProgressHUD" "$PODS_CONFIGURATION_BUILD_DIR/TesseractOCRiOS"
GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1
LD_RUNPATH_SEARCH_PATHS = $(inherited) '@executable_path/Frameworks' '@loader_path/Frameworks'
OTHER_CFLAGS = $(inherited) -iquote "$PODS_CONFIGURATION_BUILD_DIR/DocumentsOCR/DocumentsOCR.framework/Headers" -iquote "$PODS_CONFIGURATION_BUILD_DIR/GPUImage/GPUImage.framework/Headers" -iquote "$PODS_CONFIGURATION_BUILD_DIR/PodAsset/PodAsset.framework/Headers" -iquote "$PODS_CONFIGURATION_BUILD_DIR/TesseractOCRiOS/TesseractOCR.framework/Headers"
OTHER_LDFLAGS = $(inherited) -ObjC -weak_library /usr/lib/libstdc++.6.0.9.dylib -l"stdc++" -framework "DocumentsOCR" -framework "GPUImage" -framework "PodAsset" -framework "TesseractOCR"
OTHER_CFLAGS = $(inherited) -iquote "$PODS_CONFIGURATION_BUILD_DIR/DocumentsOCR/DocumentsOCR.framework/Headers" -iquote "$PODS_CONFIGURATION_BUILD_DIR/GPUImage/GPUImage.framework/Headers" -iquote "$PODS_CONFIGURATION_BUILD_DIR/PodAsset/PodAsset.framework/Headers" -iquote "$PODS_CONFIGURATION_BUILD_DIR/SVProgressHUD/SVProgressHUD.framework/Headers" -iquote "$PODS_CONFIGURATION_BUILD_DIR/TesseractOCRiOS/TesseractOCR.framework/Headers"
OTHER_LDFLAGS = $(inherited) -ObjC -weak_library /usr/lib/libstdc++.6.0.9.dylib -l"stdc++" -framework "DocumentsOCR" -framework "GPUImage" -framework "PodAsset" -framework "SVProgressHUD" -framework "TesseractOCR"
OTHER_SWIFT_FLAGS = $(inherited) "-D" "COCOAPODS"
PODS_BUILD_DIR = $BUILD_DIR
PODS_CONFIGURATION_BUILD_DIR = $PODS_BUILD_DIR/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)
@@ -2,11 +2,11 @@ ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES
CLANG_CXX_LIBRARY = compiler-default
CLANG_MODULES_AUTOLINK = YES
EMBEDDED_CONTENT_CONTAINS_SWIFT = YES
FRAMEWORK_SEARCH_PATHS = $(inherited) "$PODS_CONFIGURATION_BUILD_DIR/DocumentsOCR" "$PODS_CONFIGURATION_BUILD_DIR/GPUImage" "$PODS_CONFIGURATION_BUILD_DIR/PodAsset" "$PODS_CONFIGURATION_BUILD_DIR/TesseractOCRiOS"
FRAMEWORK_SEARCH_PATHS = $(inherited) "$PODS_CONFIGURATION_BUILD_DIR/DocumentsOCR" "$PODS_CONFIGURATION_BUILD_DIR/GPUImage" "$PODS_CONFIGURATION_BUILD_DIR/PodAsset" "$PODS_CONFIGURATION_BUILD_DIR/SVProgressHUD" "$PODS_CONFIGURATION_BUILD_DIR/TesseractOCRiOS"
GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1
LD_RUNPATH_SEARCH_PATHS = $(inherited) '@executable_path/Frameworks' '@loader_path/Frameworks'
OTHER_CFLAGS = $(inherited) -iquote "$PODS_CONFIGURATION_BUILD_DIR/DocumentsOCR/DocumentsOCR.framework/Headers" -iquote "$PODS_CONFIGURATION_BUILD_DIR/GPUImage/GPUImage.framework/Headers" -iquote "$PODS_CONFIGURATION_BUILD_DIR/PodAsset/PodAsset.framework/Headers" -iquote "$PODS_CONFIGURATION_BUILD_DIR/TesseractOCRiOS/TesseractOCR.framework/Headers"
OTHER_LDFLAGS = $(inherited) -ObjC -weak_library /usr/lib/libstdc++.6.0.9.dylib -l"stdc++" -framework "DocumentsOCR" -framework "GPUImage" -framework "PodAsset" -framework "TesseractOCR"
OTHER_CFLAGS = $(inherited) -iquote "$PODS_CONFIGURATION_BUILD_DIR/DocumentsOCR/DocumentsOCR.framework/Headers" -iquote "$PODS_CONFIGURATION_BUILD_DIR/GPUImage/GPUImage.framework/Headers" -iquote "$PODS_CONFIGURATION_BUILD_DIR/PodAsset/PodAsset.framework/Headers" -iquote "$PODS_CONFIGURATION_BUILD_DIR/SVProgressHUD/SVProgressHUD.framework/Headers" -iquote "$PODS_CONFIGURATION_BUILD_DIR/TesseractOCRiOS/TesseractOCR.framework/Headers"
OTHER_LDFLAGS = $(inherited) -ObjC -weak_library /usr/lib/libstdc++.6.0.9.dylib -l"stdc++" -framework "DocumentsOCR" -framework "GPUImage" -framework "PodAsset" -framework "SVProgressHUD" -framework "TesseractOCR"
OTHER_SWIFT_FLAGS = $(inherited) "-D" "COCOAPODS"
PODS_BUILD_DIR = $BUILD_DIR
PODS_CONFIGURATION_BUILD_DIR = $PODS_BUILD_DIR/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)
@@ -1,8 +1,8 @@
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = NO
FRAMEWORK_SEARCH_PATHS = $(inherited) "$PODS_CONFIGURATION_BUILD_DIR/DocumentsOCR" "$PODS_CONFIGURATION_BUILD_DIR/GPUImage" "$PODS_CONFIGURATION_BUILD_DIR/PodAsset" "$PODS_CONFIGURATION_BUILD_DIR/TesseractOCRiOS"
FRAMEWORK_SEARCH_PATHS = $(inherited) "$PODS_CONFIGURATION_BUILD_DIR/DocumentsOCR" "$PODS_CONFIGURATION_BUILD_DIR/GPUImage" "$PODS_CONFIGURATION_BUILD_DIR/PodAsset" "$PODS_CONFIGURATION_BUILD_DIR/SVProgressHUD" "$PODS_CONFIGURATION_BUILD_DIR/TesseractOCRiOS"
GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1
LD_RUNPATH_SEARCH_PATHS = $(inherited) '@executable_path/Frameworks' '@loader_path/Frameworks'
OTHER_CFLAGS = $(inherited) -iquote "$PODS_CONFIGURATION_BUILD_DIR/DocumentsOCR/DocumentsOCR.framework/Headers" -iquote "$PODS_CONFIGURATION_BUILD_DIR/GPUImage/GPUImage.framework/Headers" -iquote "$PODS_CONFIGURATION_BUILD_DIR/PodAsset/PodAsset.framework/Headers" -iquote "$PODS_CONFIGURATION_BUILD_DIR/TesseractOCRiOS/TesseractOCR.framework/Headers"
OTHER_CFLAGS = $(inherited) -iquote "$PODS_CONFIGURATION_BUILD_DIR/DocumentsOCR/DocumentsOCR.framework/Headers" -iquote "$PODS_CONFIGURATION_BUILD_DIR/GPUImage/GPUImage.framework/Headers" -iquote "$PODS_CONFIGURATION_BUILD_DIR/PodAsset/PodAsset.framework/Headers" -iquote "$PODS_CONFIGURATION_BUILD_DIR/SVProgressHUD/SVProgressHUD.framework/Headers" -iquote "$PODS_CONFIGURATION_BUILD_DIR/TesseractOCRiOS/TesseractOCR.framework/Headers"
PODS_BUILD_DIR = $BUILD_DIR
PODS_CONFIGURATION_BUILD_DIR = $PODS_BUILD_DIR/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)
PODS_ROOT = ${SRCROOT}/Pods
@@ -1,8 +1,8 @@
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = NO
FRAMEWORK_SEARCH_PATHS = $(inherited) "$PODS_CONFIGURATION_BUILD_DIR/DocumentsOCR" "$PODS_CONFIGURATION_BUILD_DIR/GPUImage" "$PODS_CONFIGURATION_BUILD_DIR/PodAsset" "$PODS_CONFIGURATION_BUILD_DIR/TesseractOCRiOS"
FRAMEWORK_SEARCH_PATHS = $(inherited) "$PODS_CONFIGURATION_BUILD_DIR/DocumentsOCR" "$PODS_CONFIGURATION_BUILD_DIR/GPUImage" "$PODS_CONFIGURATION_BUILD_DIR/PodAsset" "$PODS_CONFIGURATION_BUILD_DIR/SVProgressHUD" "$PODS_CONFIGURATION_BUILD_DIR/TesseractOCRiOS"
GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1
LD_RUNPATH_SEARCH_PATHS = $(inherited) '@executable_path/Frameworks' '@loader_path/Frameworks'
OTHER_CFLAGS = $(inherited) -iquote "$PODS_CONFIGURATION_BUILD_DIR/DocumentsOCR/DocumentsOCR.framework/Headers" -iquote "$PODS_CONFIGURATION_BUILD_DIR/GPUImage/GPUImage.framework/Headers" -iquote "$PODS_CONFIGURATION_BUILD_DIR/PodAsset/PodAsset.framework/Headers" -iquote "$PODS_CONFIGURATION_BUILD_DIR/TesseractOCRiOS/TesseractOCR.framework/Headers"
OTHER_CFLAGS = $(inherited) -iquote "$PODS_CONFIGURATION_BUILD_DIR/DocumentsOCR/DocumentsOCR.framework/Headers" -iquote "$PODS_CONFIGURATION_BUILD_DIR/GPUImage/GPUImage.framework/Headers" -iquote "$PODS_CONFIGURATION_BUILD_DIR/PodAsset/PodAsset.framework/Headers" -iquote "$PODS_CONFIGURATION_BUILD_DIR/SVProgressHUD/SVProgressHUD.framework/Headers" -iquote "$PODS_CONFIGURATION_BUILD_DIR/TesseractOCRiOS/TesseractOCR.framework/Headers"
PODS_BUILD_DIR = $BUILD_DIR
PODS_CONFIGURATION_BUILD_DIR = $PODS_BUILD_DIR/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)
PODS_ROOT = ${SRCROOT}/Pods
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>${EXECUTABLE_NAME}</string>
<key>CFBundleIdentifier</key>
<string>${PRODUCT_BUNDLE_IDENTIFIER}</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>${PRODUCT_NAME}</string>
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>2.0.3</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>${CURRENT_PROJECT_VERSION}</string>
<key>NSPrincipalClass</key>
<string></string>
</dict>
</plist>
@@ -0,0 +1,5 @@
#import <Foundation/Foundation.h>
@interface PodsDummy_SVProgressHUD : NSObject
@end
@implementation PodsDummy_SVProgressHUD
@end
@@ -0,0 +1,4 @@
#ifdef __OBJC__
#import <UIKit/UIKit.h>
#endif
@@ -0,0 +1,10 @@
#import <UIKit/UIKit.h>
#import "SVIndefiniteAnimatedView.h"
#import "SVProgressAnimatedView.h"
#import "SVProgressHUD.h"
#import "SVRadialGradientLayer.h"
FOUNDATION_EXPORT double SVProgressHUDVersionNumber;
FOUNDATION_EXPORT const unsigned char SVProgressHUDVersionString[];
@@ -0,0 +1,6 @@
framework module SVProgressHUD {
umbrella header "SVProgressHUD-umbrella.h"
export *
module * { export * }
}
@@ -0,0 +1,9 @@
CONFIGURATION_BUILD_DIR = $PODS_CONFIGURATION_BUILD_DIR/SVProgressHUD
GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1
HEADER_SEARCH_PATHS = "${PODS_ROOT}/Headers/Private" "${PODS_ROOT}/Headers/Public"
OTHER_LDFLAGS = -framework "QuartzCore"
PODS_BUILD_DIR = $BUILD_DIR
PODS_CONFIGURATION_BUILD_DIR = $PODS_BUILD_DIR/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)
PODS_ROOT = ${SRCROOT}
PRODUCT_BUNDLE_IDENTIFIER = org.cocoapods.${PRODUCT_NAME:rfc1034identifier}
SKIP_INSTALL = YES
+36 -17
View File
@@ -33,6 +33,8 @@ it, simply add the following line to your Podfile:
pod "DocumentsOCR"
```
You also need to set `Enable Bitcode` value to "No" in tesseract framework (target TesseractOCRiOS -> Build settings -> Enable Bitcode)
## Usage
### Import DocumentsOCR framework
@@ -46,17 +48,23 @@ pod "DocumentsOCR"
```swift
class ExampleViewController: UIViewController, DocumentScannerDelegate {
func documentScanner(scanner: DocumentScanner, willBeginScanningImage image: UIImage) {
// do something with image
}
func documentScanner(scanner: DocumentScanner, didFinishScanningWithInfo info: DocumentInfo) {
// required fucntions:
func documentScanner(_ scanner: DocumentScanner, didFinishScanningWithInfo info: DocumentInfo) {
// do something with DocumentInfo instance
}
func documentScanner(scanner: DocumentScanner, didFailWithError error: NSError) {
func documentScanner(_ scanner: DocumentScanner, didFailWithError error: NSError) {
// handle error
}
//optional functions:
func documentScanner(_ scanner: DocumentScanner, willBeginScanningImages images: [UIImage]) {
// do something with images
}
func documentScanner(_ scanner: DocumentScanner, recognitionProgress progress: Double) {
// present current progress of recognition
}
// some other code here ...
@@ -71,6 +79,12 @@ Initialize `DocumentScanner` instance with references to `UIViewController` and
var scanner = DocumentScanner(containerVC: self, withDelegate: self)
```
Optionally you can set how many photos to take and time interval between them:
```swift
scanner.photosCount = 10
scanner.takePhotoInterval = 1.0
```
### Present camera controller
Scanner instance can present view controller with camera and border (actually, container view controller will do this inside document scanner instance).
@@ -82,23 +96,28 @@ Scanner instance can present view controller with camera and border (actually, c
### Events after "take shoot" button pressed
After take shoot button pressed, these delegate methods called:
After take shoot button pressed, device take `photosCount` photos with `takePhotoInterval` time interval then these delegate methods call:
```swift
func documentScanner(scanner: DocumentScanner, willBeginScanningImage image: UIImage)
func documentScanner(_ scanner: DocumentScanner, willBeginScanningImages images: [UIImage])
```
Then if image was recognized successfull:
When one of the images recognized
```swift
func documentScanner(_ scanner: DocumentScanner, recognitionProgress: Double)
```
Then if images were recognized successfull:
```swift
func documentScanner(scanner: DocumentScanner, didFinishScanningWithInfo info: DocumentInfo)
func documentScanner(_ scanner: DocumentScanner, didFinishScanningWithInfo info: DocumentInfo)
```
If some error happened
```swift
func documentScanner(scanner: DocumentScanner, didFailWithError error: NSError)
func documentScanner(_ scanner: DocumentScanner, didFailWithError error: NSError)
```
## Author
@@ -119,7 +138,7 @@ Before using DocumentOCR, you must set Enable bitcode value to "No" in tesseract
- [x] fix minor UI defects in example
- [x] code refactoring
- [x] pod string for all versions (without using ~> version")
- [ ] improve mr code recognition
- [ ] check visa document recognitions
- [ ] unit tests for camera shoots
- [ ] take many pictures when "take shoot" button pressed, then choose best image for recognition
- [x] improve mr code recognition
- [x] check visa document recognitions
- [x] take many pictures when "take shoot" button pressed, then make best machine readable code
- [ ] tests for camera shoots