Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
thefind authored and phatmann committed May 28, 2014
0 parents commit 368fcf4
Show file tree
Hide file tree
Showing 26 changed files with 1,978 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
TFBarcodeScanner.xcodeproj/project.xcworkspace/xcuserdata
TFBarcodeScanner.xcodeproj/xcuserdata/tony.xcuserdatad
TFBarcodeScanner.xcodeproj/project.xcworkspace/xcshareddata/TFBarcodeScannerDemo.xccheckout
TFBarcodeScanner.xcodeproj/project.xcworkspace/xcshareddata/TFBarcodeScanner.xccheckout
15 changes: 15 additions & 0 deletions Demo/AppDelegate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// AppDelegate.h
// TFBarcodeScannerDemo
//
// Created by Tony Mann on 5/23/14.
// Copyright (c) 2014 TheFind. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface AppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;

@end
46 changes: 46 additions & 0 deletions Demo/AppDelegate.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
//
// AppDelegate.m
// TFBarcodeScannerDemo
//
// Created by Tony Mann on 5/23/14.
// Copyright (c) 2014 TheFind. All rights reserved.
//

#import "AppDelegate.h"

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
return YES;
}

- (void)applicationWillResignActive:(UIApplication *)application
{
// 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.
}

- (void)applicationDidEnterBackground:(UIApplication *)application
{
// 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.
}

- (void)applicationWillEnterForeground:(UIApplication *)application
{
// 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.
}

- (void)applicationDidBecomeActive:(UIApplication *)application
{
// 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.
}

- (void)applicationWillTerminate:(UIApplication *)application
{
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
197 changes: 197 additions & 0 deletions Demo/Base.lproj/Main.storyboard

Large diffs are not rendered by default.

23 changes: 23 additions & 0 deletions Demo/Images.xcassets/AppIcon.appiconset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"images" : [
{
"idiom" : "iphone",
"size" : "29x29",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "40x40",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "60x60",
"scale" : "2x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
23 changes: 23 additions & 0 deletions Demo/Images.xcassets/LaunchImage.launchimage/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"images" : [
{
"orientation" : "portrait",
"idiom" : "iphone",
"extent" : "full-screen",
"minimum-system-version" : "7.0",
"scale" : "2x"
},
{
"orientation" : "portrait",
"idiom" : "iphone",
"subtype" : "retina4",
"extent" : "full-screen",
"minimum-system-version" : "7.0",
"scale" : "2x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
40 changes: 40 additions & 0 deletions Demo/TFBarcodeScannerDemo-Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?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>CFBundleDisplayName</key>
<string>${PRODUCT_NAME}</string>
<key>CFBundleExecutable</key>
<string>${EXECUTABLE_NAME}</string>
<key>CFBundleIdentifier</key>
<string>com.thefind.${PRODUCT_NAME:rfc1034identifier}</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>${PRODUCT_NAME}</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1.0</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UIMainStoryboardFile</key>
<string>Main</string>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>armv7</string>
</array>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
</dict>
</plist>
16 changes: 16 additions & 0 deletions Demo/TFBarcodeScannerDemo-Prefix.pch
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// Prefix header
//
// The contents of this file are implicitly included at the beginning of every source file.
//

#import <Availability.h>

#ifndef __IPHONE_5_0
#warning "This project uses features only available in iOS SDK 5.0 and later."
#endif

#ifdef __OBJC__
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#endif
14 changes: 14 additions & 0 deletions Demo/ViewController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//
// ViewController.h
// TFBarcodeScannerDemo
//
// Created by Tony Mann on 5/23/14.
// Copyright (c) 2014 TheFind. All rights reserved.
//

#import <UIKit/UIKit.h>
#import "TFBarcodeScanner.h"

@interface ViewController : TFBarcodeScannerViewController

@end
104 changes: 104 additions & 0 deletions Demo/ViewController.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
//
// ViewController.m
// TFBarcodeScannerDemo
//
// Created by Tony Mann on 5/23/14.
// Copyright (c) 2014 TheFind. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@property (weak, nonatomic) IBOutlet UIActivityIndicatorView *activityIndicator;
@property (weak, nonatomic) IBOutlet UIView *overlayView;
@property (weak, nonatomic) IBOutlet UIView *resultsView;
@property (weak, nonatomic) IBOutlet UILabel *barcodeTypeLabel;
@property (weak, nonatomic) IBOutlet UILabel *barcodeStringLabel;
@property (weak, nonatomic) IBOutlet UILabel *noCameraLabel;

@end


@implementation ViewController

- (void)viewDidLoad
{
[super viewDidLoad];
self.barcodeTypes = TFBarcodeTypeEAN8 | TFBarcodeTypeEAN13 | TFBarcodeTypeUPCA | TFBarcodeTypeUPCE | TFBarcodeTypeQRCODE;
self.resultsView.alpha = 0.0f;
self.overlayView.alpha = 0.0f;
self.noCameraLabel.hidden = self.hasCamera;
}

- (UIStatusBarStyle)preferredStatusBarStyle
{
return UIStatusBarStyleLightContent;
}

#pragma mark - TFBarcodeScannerViewController

- (void)barcodePreviewWillShowWithDuration:(CGFloat)duration
{
[UIView animateWithDuration:duration animations:^{
self.overlayView.alpha = 1.0f;
} completion:^(BOOL finished) {
[self.activityIndicator stopAnimating];
}];
}

- (void)barcodePreviewWillHideWithDuration:(CGFloat)duration
{

}

- (void)barcodeWasScanned:(NSSet *)barcodes
{
[self stop];
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);

TFBarcode* barcode = [barcodes anyObject];
self.resultsView.hidden = NO;
self.barcodeTypeLabel.text = [self stringFromBarcodeType:barcode.type];
self.barcodeStringLabel.text = barcode.string;

[UIView animateWithDuration:0.2 animations:^{
self.resultsView.alpha = 1.0f;
}];
}

- (IBAction)scanAgainButtonWasTapped
{
[self start];

[UIView animateWithDuration:0.5 animations:^{
self.resultsView.alpha = 0.0f;
}];
}

#pragma mark - Private

- (NSString *)stringFromBarcodeType:(TFBarcodeType)barcodeType
{
static NSDictionary *typeMap;

if (!typeMap) {
typeMap = @{
@(TFBarcodeTypeEAN8): @"EAN8",
@(TFBarcodeTypeEAN13): @"EAN13",
@(TFBarcodeTypeUPCA): @"UPCA",
@(TFBarcodeTypeUPCE): @"UPCE",
@(TFBarcodeTypeQRCODE): @"QRCODE",
@(TFBarcodeTypeCODE128): @"CODE128",
@(TFBarcodeTypeCODE39): @"CODE39",
@(TFBarcodeTypeCODE39Mod43): @"CODE39Mod43",
@(TFBarcodeTypeCODE93): @"CODE93",
@(TFBarcodeTypePDF417): @"PDF417",
@(TFBarcodeTypeAztec): @"Aztec"
};
}

return typeMap[@(barcodeType)];
}

@end
2 changes: 2 additions & 0 deletions Demo/en.lproj/InfoPlist.strings
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/* Localized versions of Info.plist keys */

18 changes: 18 additions & 0 deletions Demo/main.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//
// main.m
// TFBarcodeScannerDemo
//
// Created by Tony Mann on 5/23/14.
// Copyright (c) 2014 TheFind. All rights reserved.
//

#import <UIKit/UIKit.h>

#import "AppDelegate.h"

int main(int argc, char * argv[])
{
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
}
}
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2014 thefind

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.
35 changes: 35 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
TFBarcodeScanner
================

Scan barcodes in iOS7 with elegance and ease

![screenshot](https://raw.githubusercontent.com/thefind/TFBarcodeScanner/master/Screenshots/screenshot.png)

iOS7 provides barcode scanning as part of the AV Framework, but it takes some work to
figure it all out and then set it up to be efficient and robust. TFBarcodeScanner makes
it super easy: create a view controller subclass of `TFBarcodeScannerViewController`,
override `barcodeWasScanned`, and you are scanning barcodes!

## Installation

We recommend using CocoaPods to install TFBarcodeScanner. Add to your Podfile:

pod 'TFBarcodeScanner'

To install manually, add TFBarcodeScanner to your project as a subproject, and
then add the TFBarcodeScanner static library in your project's Build Phases.

## Usage

1. Create a view controller that is subclassed from `TFBarcodeScannerViewController`.
Make sure that your subviews have a transparent region so the preview is visible.
1. In your `viewDidLoad` method, optionally set the `barcodeTypes` bit flag to whatever
barcode types you want to scan.
1. Override the `barcodeWasScanned` method. This returns a set of barcodes that were
recognized. You normally will call `stop` once a suitable barcode is recognized.
1. If you have UI elements that you want to overlay on top of the scanning preview,
override `barcodePreviewWillShowWithDuration` and show the elements in this method. You
will also want to override `barcodePreviewWillHideWithDuration` to hide these same
elements.

See the Demo for sample code.
Binary file added Screenshots/screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 20 additions & 0 deletions TFBarcodeScanner.podspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Pod::Spec.new do |s|
s.name = "TFBarcodeScanner"
s.version = "1.0.0"
s.summary = "Scan barcodes in iOS7 with elegance and ease"
s.description = <<-DESC
iOS7 provides barcode scanning as part of the AV Framework, but it takes
some work to figure it all out and then set it up to be efficient and robust. TFBarcodeScanner
makes it super easy: create a view controller subclass of `TFBarcodeScannerViewController`,
override `barcodeWasScanned`, and you are scanning barcodes!
DESC
s.homepage = "https://github.com/thefind/TFBarcodeScanner"
s.screenshots = "https://raw.githubusercontent.com/thefind/TFBarcodeScanner/master/Screenshots/screenshot.png"
s.license = "MIT"
s.author = { "phatmann" => "[email protected]" }
s.social_media_url = "http://twitter.com/thephatmann"
s.platform = :ios, "7.0"
s.source = { :git => "https://github.com/thefind/TFBarcodeScanner.git", :tag => "1.0.0" }
s.source_files = "TFBarcodeScanner"
s.requires_arc = true
end
Loading

0 comments on commit 368fcf4

Please sign in to comment.