From 13b8738c6ba620c517fd35f532f13294400cfd8d Mon Sep 17 00:00:00 2001 From: rpechayr Date: Sun, 6 Jun 2010 12:42:31 +0000 Subject: [PATCH] [iphone] added known issues in README when including ZXingWidget into your project, Modified ZXingWidgetController so that it know hosts a UIImagePickerController instead of SubClassing it. Please let me know if anything is broken git-svn-id: http://zxing.googlecode.com/svn/trunk@1412 59b500cc-1b3d-0410-9834-0bbf25fbcc57 --- iphone/README | 18 +++- iphone/ScanTest/Classes/RootViewController.m | 3 +- .../ScanTest.xcodeproj/project.pbxproj | 12 +-- iphone/ZXingWidget/Classes/OverlayView.h | 3 +- iphone/ZXingWidget/Classes/OverlayView.m | 86 +++++++++--------- .../Classes/ZXingWidgetController.h | 5 +- .../Classes/ZXingWidgetController.m | 91 +++++++++++++------ .../ZXingWidget.xcodeproj/project.pbxproj | 14 +-- 8 files changed, 144 insertions(+), 88 deletions(-) diff --git a/iphone/README b/iphone/README index cd1aedd8..490f9063 100644 --- a/iphone/README +++ b/iphone/README @@ -25,7 +25,7 @@ How to include ZXingWidget in a easy and clean way: 4. Finally, we need to tell your project where to find the ZXingWidget headers. Open your "Project Settings" and go to the "Build" tab. Look for "Header Search Paths" and double-click it. Add the relative path from your project's directory to the - "zxing/iphone/ZXingWidget/Classes" directory. Make sure you click the checkbox "relative path" ! + "zxing/iphone/ZXingWidget/Classes" directory. Make sure you click the checkbox "recursive path" ! 5. Ultimately you need to make a tweak so that ZXing actually decodes barcode. In target section, double click on your project target, and go to the build tab. Look for the "Exported Symbols Files" and @@ -33,4 +33,18 @@ How to include ZXingWidget in a easy and clean way: This will tell the linket to actually link with some key classes so that this code registers the necessary decoders. - 6. You're ready to go. Just #import from anywhere and it should work ! \ No newline at end of file + 6. You're ready to go. Just #import from anywhere and it should work ! + +Know issues for above steps to include: +====================================== + - It can happen that when trying to build your own project with ZXoingWidgetController you get linker errors like + "undefined reference to". If this error looks like a c++ undefined reference, then renaming main.m into main.mm (Objectice-C++ source suffix) + may fix the problem + + - If you have building error like " ... : No such file or directory", then it is a classical error, it means that the path to includes is not well + specified. The best way to fix this is to look at the Build Command that failed. To do that, click on the lower right corner of your XCode project, + you should see the build command that failed. Click on it and expand it by cliking on the "more" symbols that just appeared. This will make appear + the exact command line instruction that is ran and fails. You can then make sure that the Header search path you specified is there, and you can also + copy/paste this line into your terminal and try to see if you can reproduce/fix the error by adding the right path to the compiler. Once is is fixed, + you should have an idea of what's the problem and accordingly modify your Header Search Path. + \ No newline at end of file diff --git a/iphone/ScanTest/Classes/RootViewController.m b/iphone/ScanTest/Classes/RootViewController.m index 2af80bbc..20ef8344 100644 --- a/iphone/ScanTest/Classes/RootViewController.m +++ b/iphone/ScanTest/Classes/RootViewController.m @@ -35,7 +35,7 @@ - (IBAction)scanPressed:(id)sender { //UIImagePickerController *picker = [[UIImagePickerController alloc] init]; [self presentModalViewController:scanController - animated:YES]; + animated:NO]; // [self.navigationController pushViewController:scanController animated:true]; } @@ -82,7 +82,6 @@ [resultsView setText:resultsToDisplay]; [resultsView setNeedsDisplay]; } - } - (void)cancelled { diff --git a/iphone/ScanTest/ScanTest.xcodeproj/project.pbxproj b/iphone/ScanTest/ScanTest.xcodeproj/project.pbxproj index af586490..fa44d4c6 100755 --- a/iphone/ScanTest/ScanTest.xcodeproj/project.pbxproj +++ b/iphone/ScanTest/ScanTest.xcodeproj/project.pbxproj @@ -8,7 +8,7 @@ /* Begin PBXBuildFile section */ 1D3623260D0F684500981E51 /* ScanTestAppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D3623250D0F684500981E51 /* ScanTestAppDelegate.m */; }; - 1D60589B0D05DD56006BFB54 /* main.mm in Sources */ = {isa = PBXBuildFile; fileRef = 29B97316FDCFA39411CA2CEA /* main.mm */; }; + 1D60589B0D05DD56006BFB54 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 29B97316FDCFA39411CA2CEA /* main.m */; }; 1D60589F0D05DD5A006BFB54 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1D30AB110D05D00D00671497 /* Foundation.framework */; }; 1DF5F4E00D08C38300B7A737 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1DF5F4DF0D08C38300B7A737 /* UIKit.framework */; }; 1F027F7F11A7BADA006B06DE /* libZXingWidget.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 1F027F7E11A7BAD4006B06DE /* libZXingWidget.a */; }; @@ -52,7 +52,7 @@ 28C286DF0D94DF7D0034E888 /* RootViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RootViewController.h; sourceTree = ""; }; 28C286E00D94DF7D0034E888 /* RootViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RootViewController.m; sourceTree = ""; }; 28F335F01007B36200424DE2 /* RootViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = RootViewController.xib; sourceTree = ""; }; - 29B97316FDCFA39411CA2CEA /* main.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = main.mm; sourceTree = ""; }; + 29B97316FDCFA39411CA2CEA /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 8D1107310486CEB800E47090 /* ScanTest-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "ScanTest-Info.plist"; plistStructureDefinitionIdentifier = "com.apple.xcode.plist.structure-definition.iphone.info-plist"; sourceTree = ""; }; E5345BF01198D81A000CB77F /* AudioToolbox.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AudioToolbox.framework; path = System/Library/Frameworks/AudioToolbox.framework; sourceTree = SDKROOT; }; E5345FD6119B27D2000CB77F /* libZXingWidget.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; name = libZXingWidget.a; path = "build/Debug-iphoneos/libZXingWidget.a"; sourceTree = ""; }; @@ -129,7 +129,7 @@ isa = PBXGroup; children = ( 28A0AAE50D9B0CCF005BE974 /* ScanTest_Prefix.pch */, - 29B97316FDCFA39411CA2CEA /* main.mm */, + 29B97316FDCFA39411CA2CEA /* main.m */, ); name = "Other Sources"; sourceTree = ""; @@ -236,7 +236,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 1D60589B0D05DD56006BFB54 /* main.mm in Sources */, + 1D60589B0D05DD56006BFB54 /* main.m in Sources */, 1D3623260D0F684500981E51 /* ScanTestAppDelegate.m in Sources */, 28C286E10D94DF7D0034E888 /* RootViewController.m in Sources */, ); @@ -303,7 +303,7 @@ GCC_WARN_UNUSED_VARIABLE = YES; HEADER_SEARCH_PATHS = "../ZXingWidget/Classes/**"; PREBINDING = NO; - SDKROOT = iphoneos3.1.3; + SDKROOT = iphoneos3.1; }; name = Debug; }; @@ -318,7 +318,7 @@ HEADER_SEARCH_PATHS = "../ZXingWidget/Classes/**"; OTHER_CFLAGS = "-DNS_BLOCK_ASSERTIONS=1"; PREBINDING = NO; - SDKROOT = iphoneos3.1.3; + SDKROOT = iphoneos3.1; }; name = Release; }; diff --git a/iphone/ZXingWidget/Classes/OverlayView.h b/iphone/ZXingWidget/Classes/OverlayView.h index 019ee1ef..d9f6d350 100755 --- a/iphone/ZXingWidget/Classes/OverlayView.h +++ b/iphone/ZXingWidget/Classes/OverlayView.h @@ -26,12 +26,11 @@ BOOL oneDMode; } -//@property (nonatomic, retain) UIImage* image; @property (nonatomic, retain) NSArray* points; @property (nonatomic, assign) id delegate; @property (nonatomic, assign) BOOL oneDMode; -- (id)initWithCancelEnabled:(BOOL)cancelEnabled frame:(CGRect)frame; +- (id)initWithFrame:(CGRect)theFrame cancelEnabled:(BOOL)isCancelEnabled oneDMode:(BOOL)isOneDModeEnabled; - (CGRect)cropRect; diff --git a/iphone/ZXingWidget/Classes/OverlayView.m b/iphone/ZXingWidget/Classes/OverlayView.m index 27ebd44c..b8e2355e 100755 --- a/iphone/ZXingWidget/Classes/OverlayView.m +++ b/iphone/ZXingWidget/Classes/OverlayView.m @@ -22,28 +22,28 @@ static const CGFloat kPadding = 10; @synthesize delegate, oneDMode; @synthesize points = _points; -//@synthesize image; //////////////////////////////////////////////////////////////////////////////////////////////////// -- (id)initWithCancelEnabled:(BOOL)cancelEnabled frame:(CGRect)frame { - if( self = [super initWithFrame:frame] ) { +- (id) initWithFrame:(CGRect)theFrame cancelEnabled:(BOOL)isCancelEnabled oneDMode:(BOOL)isOneDModeEnabled { + if( self = [super initWithFrame:theFrame] ) { self.backgroundColor = [UIColor clearColor]; - } - if (cancelEnabled) { - cancelButton = [UIButton buttonWithType:UIButtonTypeRoundedRect]; - [cancelButton setTitle:@"Cancel" forState:UIControlStateNormal]; - if (oneDMode) { - [cancelButton setTransform:CGAffineTransformMakeRotation(M_PI/2)]; - [cancelButton setFrame:CGRectMake(20, 175, 45, 130)]; - } - else { - [cancelButton setFrame:CGRectMake(95, 420, 130, 45)]; - } - - [cancelButton addTarget:self action:@selector(cancel:) forControlEvents:UIControlEventTouchUpInside]; - [self addSubview:cancelButton]; - } + self.oneDMode = isOneDModeEnabled; + if (isCancelEnabled) { + cancelButton = [UIButton buttonWithType:UIButtonTypeRoundedRect]; + [cancelButton setTitle:@"Cancel" forState:UIControlStateNormal]; + if (oneDMode) { + [cancelButton setTransform:CGAffineTransformMakeRotation(M_PI/2)]; + [cancelButton setFrame:CGRectMake(20, 175, 45, 130)]; + } + else { + [cancelButton setFrame:CGRectMake(95, 420, 130, 45)]; + } + + [cancelButton addTarget:self action:@selector(cancel:) forControlEvents:UIControlEventTouchUpInside]; + [self addSubview:cancelButton]; + } + } return self; } @@ -80,11 +80,11 @@ static const CGFloat kPadding = 10; - (void)drawRect:(CGRect)rect { [super drawRect:rect]; CGContextRef c = UIGraphicsGetCurrentContext(); - + CGRect cropRect = [self cropRect]; if (nil != _points) { -// [imageView.image drawAtPoint:cropRect.origin]; + // [imageView.image drawAtPoint:cropRect.origin]; } CGFloat white[4] = {1.0f, 1.0f, 1.0f, 1.0f}; @@ -92,7 +92,7 @@ static const CGFloat kPadding = 10; CGContextSetFillColor(c, white); [self drawRect:cropRect inContext:c]; -// CGContextSetStrokeColor(c, white); + // CGContextSetStrokeColor(c, white); // CGContextSetStrokeColor(c, white); CGContextSaveGState(c); if (oneDMode) { @@ -140,8 +140,8 @@ static const CGFloat kPadding = 10; for( NSValue* value in _points ) { CGPoint point = [value CGPointValue]; smallSquare.origin = CGPointMake( - cropRect.origin.x + point.x - smallSquare.size.width / 2, - cropRect.origin.y + point.y - smallSquare.size.height / 2); + cropRect.origin.x + point.x - smallSquare.size.width / 2, + cropRect.origin.y + point.y - smallSquare.size.height / 2); [self drawRect:smallSquare inContext:c]; } } @@ -151,26 +151,26 @@ static const CGFloat kPadding = 10; //////////////////////////////////////////////////////////////////////////////////////////////////// /* -- (void) setImage:(UIImage*)image { - if( nil == _imageView ) { - _imageView = [[UIImageView alloc] initWithImage:image]; - _imageView.alpha = 0.5; - } else { - _imageView.image = image; - } - - CGRect frame = _imageView.frame; - frame.origin.x = self.cropRect.origin.x; - frame.origin.y = self.cropRect.origin.y; - _imageView.frame = frame; - - [_points release]; - _points = nil; - self.backgroundColor = [UIColor clearColor]; - - [self setNeedsDisplay]; -} -*/ + - (void) setImage:(UIImage*)image { + if( nil == _imageView ) { + _imageView = [[UIImageView alloc] initWithImage:image]; + _imageView.alpha = 0.5; + } else { + _imageView.image = image; + } + + CGRect frame = _imageView.frame; + frame.origin.x = self.cropRect.origin.x; + frame.origin.y = self.cropRect.origin.y; + _imageView.frame = frame; + + [_points release]; + _points = nil; + self.backgroundColor = [UIColor clearColor]; + + [self setNeedsDisplay]; + } + */ //////////////////////////////////////////////////////////////////////////////////////////////////// - (UIImage*) image { diff --git a/iphone/ZXingWidget/Classes/ZXingWidgetController.h b/iphone/ZXingWidget/Classes/ZXingWidgetController.h index 252d4aa1..522cfb67 100755 --- a/iphone/ZXingWidget/Classes/ZXingWidgetController.h +++ b/iphone/ZXingWidget/Classes/ZXingWidgetController.h @@ -22,8 +22,10 @@ @protocol ZXingDelegate; -@interface ZXingWidgetController : UIImagePickerController { +//@interface ZXingWidgetController : UIImagePickerController { +@interface ZXingWidgetController : UIViewController { ParsedResult *result; + UIImagePickerController *imagePicker; NSArray *actions; OverlayView *overlayView; SystemSoundID beepSound; @@ -43,6 +45,7 @@ - (id)initWithDelegate:(id)delegate showCancel:(BOOL)shouldShowCancel OneDMode:(BOOL)shouldUseoOneDMode; - (BOOL)fixedFocus; +- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker; @end @protocol ZXingDelegate diff --git a/iphone/ZXingWidget/Classes/ZXingWidgetController.m b/iphone/ZXingWidget/Classes/ZXingWidgetController.m index 672d3761..49ac8ca6 100755 --- a/iphone/ZXingWidget/Classes/ZXingWidgetController.m +++ b/iphone/ZXingWidget/Classes/ZXingWidgetController.m @@ -34,6 +34,8 @@ CGImageRef UIGetScreenImage(void); @property BOOL showCancel; @property BOOL oneDMode; +@property (nonatomic, retain) UIImagePickerController* imagePicker; + @end @@ -44,33 +46,50 @@ CGImageRef UIGetScreenImage(void); @synthesize result, actions, delegate, soundToPlay; @synthesize overlayView; @synthesize oneDMode, showCancel; +@synthesize imagePicker; + + +-(void)loadImagePicker { + if (self.imagePicker) + { + [imagePicker release]; + imagePicker = nil; + } + UIImagePickerController* imController = [[UIImagePickerController alloc] init]; + self.imagePicker = imController; + imagePicker.delegate = self; + [imController release]; + imagePicker.wantsFullScreenLayout = YES; + if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) + imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera; + float zoomFactor = CAMERA_SCALAR; + if ([self fixedFocus]) { + zoomFactor *= 2.0; + } + if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) + imagePicker.cameraViewTransform = CGAffineTransformScale( + imagePicker.cameraViewTransform, zoomFactor, zoomFactor); + if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) + { + imagePicker.showsCameraControls = NO; + imagePicker.cameraOverlayView = overlayView; + imagePicker.allowsEditing = NO; + } +} - (id)initWithDelegate:(id)scanDelegate showCancel:(BOOL)shouldShowCancel OneDMode:(BOOL)shouldUseoOneDMode { if (self = [super init]) { [self setDelegate:scanDelegate]; self.oneDMode = shouldUseoOneDMode; self.showCancel = shouldShowCancel; - beepSound = -1; self.wantsFullScreenLayout = YES; - if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) - self.sourceType = UIImagePickerControllerSourceTypeCamera; - float zoomFactor = CAMERA_SCALAR; - if ([self fixedFocus]) { - zoomFactor *= 2.0; - } - if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) - self.cameraViewTransform = CGAffineTransformScale( - self.cameraViewTransform, zoomFactor, zoomFactor); - overlayView = [OverlayView alloc]; - [overlayView setOneDMode:oneDMode]; - overlayView = [overlayView initWithCancelEnabled:showCancel frame:[UIScreen mainScreen].bounds]; - [overlayView setDelegate:self]; - if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) - { - self.showsCameraControls = NO; - self.cameraOverlayView = overlayView; - self.allowsEditing = NO; // [[NSUserDefaults standardUserDefaults] boolForKey:@"allowEditing"]; - } + beepSound = -1; + OverlayView *theOverLayView = [[OverlayView alloc] initWithFrame:[UIScreen mainScreen].bounds + cancelEnabled:showCancel + oneDMode:oneDMode]; + [theOverLayView setDelegate:self]; + self.overlayView = theOverLayView; + [theOverLayView release]; } return self; @@ -80,13 +99,15 @@ CGImageRef UIGetScreenImage(void); if (beepSound != -1) { AudioServicesDisposeSystemSoundID(beepSound); } - self.cameraOverlayView = nil; + imagePicker.cameraOverlayView = nil; + [imagePicker release]; [overlayView release]; [super dealloc]; } - (void)cancelled { NSLog(@"cancelled called in ZXingWidgetController"); + [[UIApplication sharedApplication] setStatusBarHidden:NO]; wasCancelled = true; if (delegate != nil) { [delegate cancelled]; @@ -112,6 +133,8 @@ CGImageRef UIGetScreenImage(void); - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; + self.wantsFullScreenLayout = YES; + //[[UIApplication sharedApplication] setStatusBarHidden:YES]; if ([self soundToPlay] != nil) { OSStatus error = AudioServicesCreateSystemSoundID((CFURLRef)[self soundToPlay], &beepSound); if (error != kAudioServicesNoError) { @@ -121,16 +144,32 @@ CGImageRef UIGetScreenImage(void); } - (void)viewDidAppear:(BOOL)animated { + NSLog(@"View did appear"); [super viewDidAppear:animated]; + [[UIApplication sharedApplication] setStatusBarHidden:YES]; + //self.wantsFullScreenLayout = YES; + [self loadImagePicker]; + self.view = imagePicker.view; + [overlayView setPoints:nil]; wasCancelled = false; - [NSTimer scheduledTimerWithTimeInterval: FIRST_TAKE_DELAY - target: self - selector: @selector(takePicture:) - userInfo: nil - repeats: NO]; + if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) { + + [NSTimer scheduledTimerWithTimeInterval: FIRST_TAKE_DELAY + target: self + selector: @selector(takePicture:) + userInfo: nil + repeats: NO]; + } +} + +- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker { + //self.wantsFullScreenLayout = NO; + [UIApplication sharedApplication].statusBarHidden = NO; + [self cancelled]; } + - (CGImageRef)CGImageRotated90:(CGImageRef)imgRef { CGFloat angleInRadians = -90 * (M_PI / 180); diff --git a/iphone/ZXingWidget/ZXingWidget.xcodeproj/project.pbxproj b/iphone/ZXingWidget/ZXingWidget.xcodeproj/project.pbxproj index 3fea652d..8c0bc724 100644 --- a/iphone/ZXingWidget/ZXingWidget.xcodeproj/project.pbxproj +++ b/iphone/ZXingWidget/ZXingWidget.xcodeproj/project.pbxproj @@ -1111,7 +1111,7 @@ ); PRESERVE_DEAD_CODE_INITS_AND_TERMS = NO; PRODUCT_NAME = ZXingWidget; - SDKROOT = iphoneos3.1.3; + SDKROOT = iphonesimulator3.0; SEPARATE_STRIP = NO; SKIP_INSTALL = YES; STANDARD_C_PLUS_PLUS_LIBRARY_TYPE = dynamic; @@ -1130,36 +1130,38 @@ HEADER_SEARCH_PATHS = ../../cpp/core/src; INSTALL_PATH = /usr/local/lib; PRODUCT_NAME = ZXingWidget; - SDKROOT = iphoneos3.1.3; + SDKROOT = iphonesimulator3.0; }; name = Release; }; 1DEB922308733DC00010E9CD /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { - ARCHS = "$(ARCHS_STANDARD_32_BIT)"; + ARCHS = "$(ARCHS_UNIVERSAL_IPHONE_OS)"; GCC_C_LANGUAGE_STANDARD = c99; GCC_OPTIMIZATION_LEVEL = 0; + GCC_VERSION = com.apple.compilers.llvm.clang.1_0; GCC_WARN_ABOUT_RETURN_TYPE = YES; GCC_WARN_UNUSED_VARIABLE = YES; IPHONEOS_DEPLOYMENT_TARGET = 3.1.3; OTHER_LDFLAGS = "-ObjC"; PREBINDING = NO; - SDKROOT = iphoneos3.1.3; + SDKROOT = iphoneos3.1; }; name = Debug; }; 1DEB922408733DC00010E9CD /* Release */ = { isa = XCBuildConfiguration; buildSettings = { - ARCHS = "$(ARCHS_STANDARD_32_BIT)"; + ARCHS = "$(ARCHS_UNIVERSAL_IPHONE_OS)"; GCC_C_LANGUAGE_STANDARD = c99; + GCC_VERSION = com.apple.compilers.llvm.clang.1_0; GCC_WARN_ABOUT_RETURN_TYPE = YES; GCC_WARN_UNUSED_VARIABLE = YES; IPHONEOS_DEPLOYMENT_TARGET = 3.1.3; OTHER_LDFLAGS = "-ObjC"; PREBINDING = NO; - SDKROOT = iphoneos3.1.3; + SDKROOT = iphoneos3.1; }; name = Release; }; -- 2.20.1