Implementing ZBar QR Code Reader in UIView - objective-c

I really need help here. I'm pretty new to iOS/Objective-C so sorry if the problem resolution is obvious or if my code is terrible. Be easy on me!! :-)
I'm struggling to integrate ZBarSDK for reading QR Codes into an iPad app i'm building. If I use ZBarReaderController (of which there are plenty of tutorials and guides on implementing), it works fine. However I want to make the camera come up in a UIView as opposed to the fullscreen camera.
Now I have gotten as far as making the camera view (readerView) come up in the UIView (ZBarReaderView) as expected, but I get an error when it scans a code. The error does not come up until a code is scanned making me believe this is either delegate related or something else.
Here's the important parts of my code: (ZBarSDK.h is imported at the PCH file)
SignInViewController.h
#import <UIKit/UIKit.h>
#import <AVFoundation/AVFoundation.h>
#class AVCaptureSession, AVCaptureDevice;
#interface SignInViewController : UIViewController
< ZBarReaderDelegate >
{
ZBarReaderView *readerView;
UITextView *resultText;
}
#property (nonatomic, retain) UIImagePickerController *imgPicker;
#property (strong, nonatomic) IBOutlet UITextView *resultText;
#property (strong, nonatomic) IBOutlet ZBarReaderView *readerView;
-(IBAction)StartScan:(id) sender;
SignInViewController.m
#import "SignInViewController.h"
#interface SignInViewController ()
#end
#implementation SignInViewController
#synthesize resultText, readerView;
-(IBAction)StartScan:(id) sender
{
readerView = [ZBarReaderView new];
readerView.readerDelegate = self;
readerView.tracksSymbols = NO;
readerView.frame = CGRectMake(30,70,230,230);
readerView.torchMode = 0;
readerView.device = [self frontFacingCameraIfAvailable];
ZBarImageScanner *scanner = readerView.scanner;
[scanner setSymbology: ZBAR_I25
config: ZBAR_CFG_ENABLE
to: 0];
[self relocateReaderPopover:[self interfaceOrientation]];
[readerView start];
[self.view addSubview: readerView];
resultText.hidden=NO;
}
- (void) readerControllerDidFailToRead: (ZBarReaderController*) reader
withRetry: (BOOL) retry{
NSLog(#"the image picker failing to read");
}
- (void) imagePickerController: (UIImagePickerController*) reader didFinishPickingMediaWithInfo: (NSDictionary*) info
{
NSLog(#"the image picker is calling successfully %#",info);
id<NSFastEnumeration> results = [info objectForKey: ZBarReaderControllerResults];
ZBarSymbol *symbol = nil;
NSString *hiddenData;
for(symbol in results)
hiddenData=[NSString stringWithString:symbol.data];
NSLog(#"the symbols is the following %#",symbol.data);
resultText.text=symbol.data;
NSLog(#"BARCODE= %#",symbol.data);
NSLog(#"SYMBOL : %#",hiddenData);
resultText.text=hiddenData;
}
The error I get when a code is scanned:
2012-12-16 14:28:32.797 QRTestApp[7970:907] -[SignInViewController readerView:didReadSymbols:fromImage:]: unrecognized selector sent to instance 0x1e88b1c0
2012-12-16 14:28:32.799 QRTestApp[7970:907] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[SignInViewController readerView:didReadSymbols:fromImage:]: unrecognized selector sent to instance 0x1e88b1c0'
I'm not too worried about what happens with the results just yet, just want to get over this error. Took me ages just to get the camera to come up in the UIView due to severe lack of tutorial or documentation on ZBarReaderView (for beginners anyway). Thanks all.

I fixed this. Had an incorrect delegate name. It should have been "ZbarReaderViewDelegate". I was missing the "view" part. Doh!!
#interface SignInViewController : UIViewController
< ZBarReaderViewDelegate >
{
ZBarReaderView *readerView;
UITextView *resultText;
}

Related

Objective c + Tesseract issue

I've simple code that performs recognition text on image as below:
#import "ParseLinesFromImage.h"
#import <TesseractOCR/TesseractOCR.h>
#implementation ParseLinesFromImage
- (void) performRecognitionWithImage:(UIImage*)image
{ dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
G8Tesseract* tesseract = [[G8Tesseract alloc] initWithLanguage:#"eng"];
tesseract.language = #"eng";
tesseract.engineMode = G8OCREngineModeTesseractCubeCombined;
tesseract.pageSegmentationMode = G8PageSegmentationModeAuto;
tesseract.maximumRecognitionTime = 60.0;
tesseract.image = [image g8_blackAndWhite];
BOOL recognized = [tesseract recognize];
if (recognized == YES)
{
NSDictionary *array = [self parseValidLines:tesseract.recognizedText];
dispatch_async(dispatch_get_main_queue(), ^{
[self.delegate sucessWithText:array];
});
}
else
{
dispatch_async(dispatch_get_main_queue(), ^{
[self.delegate failedTextReader:nil];
});
}
});
}
Code define in .h file like below:
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#protocol ParseLinesFromImageDelegate<NSObject>
#required
-(void) sucess:(nullable NSDictionary*)info;
-(void) failed:(nullable NSError*) error;
#end
#interface ParseLinesFromImage: NSObject
#property (nonatomic, weak, nullable) id <ParseLinesFromImageDelegate> delegate;
- (void) performRecognitionWithImage:(UIImage* _Nonnull)image;
#end
But when running to line marked as 1, system push an exeption
"Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIImage g8_blackAndWhite]: unrecognized selector sent to instance 0x60c0000b9e00'"
In my view it may be an ambiguous between UIImage+G8Filters.h(define g8_blackAndWhite) and UIImage but I look into TesseractOCR example, it's the same as mine.
Please help me to find out the reason and how to fix it, thanks.
PS: Thanks you for reading my question, after google and follow answer from https://github.com/gali8/Tesseract-OCR-iOS/wiki/Installation (side note), the issue goes away and in my case, I added _all-load to my project.

How to read infos from /S/L/E kext info.plist file?

I’m just a newbie in Mac OS X programming so please, be patient with me. I’m trying to make a cocoa app which the goal is to read some infos from Info.plist kext’s file, which the full path is /System/Library/Extensions/NVDAResman.kext/Contents/Info.plist
h.
#import <Cocoa/Cocoa.h>
#interface AppDelegate : NSObject <NSApplicationDelegate>
#property (weak) IBOutlet NSTextField *nvidiaNameTextField;
#end
m.
#import "AppDelegate.h"
#interface AppDelegate ()
#property (weak) IBOutlet NSWindow *window;
#end
#implementation AppDelegate
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
// Insert code here to initialize your application
[self setnvidiaNameTextField];
}
- (void)applicationWillTerminate:(NSNotification *)aNotification {
// Insert code here to tear down your application
}
// This will allow the application to quit instead of just closing the window
- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)sender
{
return YES;
}
// Find NVIDIA Kernel Extension Name
-(void)setnvidiaNameTextField
{
NSString *nvidiaNameTextField = [[NSBundle mainBundle] objectForInfoDictionaryKey:#"CFBundleName"];
self.nvidiaNameTextField.stringValue = [NSString stringWithFormat:#"%#", nvidiaNameTextField];
}
#end
it works but with my project Info.plist file, and it’s not what I want.
So my question is how can I read Info.plist from NVDAResman.kext?
Thank you in advance
PS: I’m using Xcode 7.1 beta (7B60)
NSDictionary *dict = [[NSDictionary alloc] initWithContentsOfFile:#"/System/Library/Extensions/NVDAResman.kext/Contents/Info.plist"];
Please mind that any search using "[NSBundle mainBundle]" will results within your application package (under .app folder structure). Also if you plan to sandbox your application the above code will not work and there is no solution to make it work with Sandboxing (security of OS X platform).
here’s how I did it (thanks to xhruso00)
m.
// Find NVIDIA Kernel Extension Name
-(void)setnvidiaVersionTextField
{
NSDictionary *infoDict = [[NSDictionary alloc] initWithContentsOfFile:#"/System/Library/Extensions/NVDAResman.kext/Contents/Info.plist"];
NSString* nvidiaVersionTextField = [infoDict objectForKey:#"CFBundleName"];
self.nvidiaVersionTextField.stringValue = [NSString stringWithFormat:#"%#", nvidiaVersionTextField];
}

Why I get this error? unrecognized selector sent to instance [duplicate]

This question already has an answer here:
Closed 10 years ago.
Possible Duplicate:
I want highlight text on UIWebView
I'm getting the error "unrecognized selector sent to instance 0x756cef0" when calling -[UIWebView highlightAllOccurencesOfString:]. The selector was declared in WBHighlight.h and I use forward declaration in WBSecondViewController.h.
WBSecondViewController.h
#class WBHighlight;
#import <UIKit/UIKit.h>
#interface WBSecondViewController : UIViewController <UIWebViewDelegate, UIScrollViewDelegate>
#property (weak, nonatomic) IBOutlet WBHighlight *webView;
- (IBAction)searchButtonPressed:(id)sender;
- (IBAction)clearHighlights:(id)sender;
#end
WBSecondViewController.m
#import "WBSecondViewController.h"
#import "WBHighlight.h"
#interface WBSecondViewController ()
#end
#implementation WBSecondViewController
-(IBAction)searchButtonPressed:(id)sender{
NSLog(#"highlighttes");
[_webView highlightAllOccurencesOfString:#"cat"];
}
-(IBAction)clearHighlights:(id)sender{
[_webView removeAllHighlights];
}
WBHighlight.h
#import <UIKit/UIKit.h>
#interface WBHighlight : UIWebView{
}
- (NSInteger)highlightAllOccurencesOfString:(NSString*)str;
- (void)removeAllHighlights;
#end
WBHighlight.m
#import "WBHighlight.h"
- (NSInteger)highlightAllOccurencesOfString:(NSString*)str
{
NSString *path = [[NSBundle mainBundle] pathForResource:#"UIWebViewSearch" ofType:#"js"];
NSString *jsCode = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
[self stringByEvaluatingJavaScriptFromString:jsCode];
NSString *startSearch = [NSString stringWithFormat:#"uiWebview_HighlightAllOccurencesOfString('%#')",str];
[self stringByEvaluatingJavaScriptFromString:startSearch];
NSString *result = [self stringByEvaluatingJavaScriptFromString:#"uiWebview_SearchResultCount"];
return [result integerValue];
}
- (void)removeAllHighlights
{
[self stringByEvaluatingJavaScriptFromString:#"uiWebview_RemoveAllHighlights()"];
}
#end
any idea?
This issue is due to you connected the WBHighlight outlet to a UIWebView.
Probably the WBHighlight is a subclassed UIWebView in which highlightAllOccurencesOfString: method is declared and defined. This method is not present in standard UIWebView, that's why it is throwing an error like: unrecognized selector sent to instance.
You need to change the class of UIWebView to WBHighlight in interface builder.
Go to your identity inspector
Select your WebView
Change the class of UIWebView to WBHighlight
Hekiru, You need to make the object of WBHighlight in order to call that method. And, for this you need to import that class and make object.
Let say,
WBHighlight *objWBHighlight = [WBHighlight new];
//Then, call that required method:
int someVarToAssign = [objWBHighlight highlightAllOccurencesOfString:#"fsfsf"];
Hope, it'll sort-out your problem.Try it.
In any concern let me know. :)

Objective-C get slider value and display it on text box

I got a very simple app. it gets slider value and display it on text box. The interface and implementation is as follow:
#import <Foundation/Foundation.h>
#interface HelloWorld : NSObject
#property (assign) IBOutlet NSTextField *Tf;
#property (assign) IBOutlet NSSliderCell *Sc;
#end
#import "HelloWorld.h"
#implementation HelloWorld
#synthesize Tf;
#synthesize Sc;
- (IBAction)Pressed:(id)sender {
[Tf setStringValue:#"Hey"];
}
- (IBAction)Scroll:(id)sender {
[Tf setStringValue: [Sc indexOfTickMarkAtPoint]];
}
#end
The UI:
Problem:
The app crashes when I move the slider.
indexOfTickMarkAtPoint returns NSInteger but setStringValue: wants (somewhat obviously) a string. Look at the documentation for NSString method stringWithFormat: for a description of how to do the conversion.
Something like:
[Tf setStringValue:[NSString stringWithFormat:#"%d", [Sc indexOfTickMarkAtPoint]]];
Whats happening is its an NSInteger and not a pointer to an Object
[Tf setIntegerValue:[Sc indexOfTickMarkAtPoint]];

EXC_BAD_ACCESS iPhone Dev

I am very new to development in Objective C but have a lot of experience in object orientated development in c# ASP. I've been trying to make a simple iPhone app where a PickerView control is accessing a data source.
In my header file (InstaTwitViewController.h) I have declared the following:
#interface InstaTwitViewController : UIViewController
<UIPickerViewDataSource, UIPickerViewDelegate> {
NSArray* activities;
NSArray* feelings;
}
I now try to inititialise my arrays in the viewDidLoad functions in my InstaTwitViewController.m file:
activities = [[NSArray alloc] initWithObjects:#"sleeping", #"eating", #"thinking", nil];
feelings = [[NSArray alloc] initWithObjects:#"psyched", #"sad", #"happy", nil];
but when I run the code on the simulator I get a Thread 1: Program recieved signal "ESC_BAD_ACCESS" error on the first line of code (where I allocate data to the activities array).
I put a break point on the line and it recognises it as an NSArray called activities but says "Invalid Summary" at the end.
Does anyone know why I am getting this error? I have looked at many threads about the ESC_BAD_ACCESS error but none have seemed to have helped me.
.h
#interface InstaTwitViewController : UIViewController <UIPickerViewDataSource, UIPickerViewDelegate> {
NSArray* activities;
NSArray* feelings;
}
#property (nonatomic, retain) NSArray* activities;
#property (nonatomic, retain) NSArray* feelings;
#end
.m
#import "your.h"
#implementation InstaTwitViewController
#synthesize activities, feelings;
- (void)viewDidLoad {
[super viewDidLoad];
[self.activities addObject ~ /* Do your code here */];
}
#end
Becareful you should stay on self.~ if you don't want to lose your value.
By the way, I am Korean~ ^^;