Adding external files in ios

Hi guys,

I am trying to implement QR code reader in IOS.  Based on Lerg’s QR scanner, it uses this , https://github.com/mikebuss/MTBBarcodeScanner , which i am trying to use. Using the ‘App template from Corona enterprise’.

I tried installing it using cocoaPods, but some build errors related to ‘i386 x64_86’ appeared and I couldn’t fix it. Does cocoaPods work with Corona Enterprise ?

Then now, I am trying to do the manual method, where I just copy “MTBBarcodeScanner.h” & “MTBBarcodeScanner.m” into my project folder. 

I am facing this build error in file “MTBBarcodeScanner.m” :

@implementation MTBBarcodeScanner "cannot synthesize weak property in file using manual reference counting"

Please help.

Thanks

With out seeing your source code, look to see if you’re specifying “weak” on one of the properties and try removing it.

Rob

Thanks. That solved it. There was a ‘weak’ property for one of the item at the top of the .m file which I didn’t know about ( i am new to ObjC )

For those trying to do the same, here is what I did. 

  1. Copy the files “MTBBarcodeScanner.h” & “MTBBarcodeScanner.m” into the project (drag and drop works fine for me).

  2. Change the ‘weak’ words to ‘strong’. In this project, there was only 1 location.

  3. To view the live-camera on screen, you will need to use the window in focus (not the runtime.appWindow).

Here is a code snippet, based on the project template ‘App’. There are some commented lines in here for testing / experimental purposes.

Thanks for Sergey for the QR code plugin and the idea as starting point.

#import "PluginLibrary.h" #include "CoronaRuntime.h" #import "MTBBarcodeScanner.h" #import \<UIKit/UIKit.h\> #import \<AVFoundation/AVFoundation.h\> .. Your other code here ... // [Lua] library.show( word ) int PluginLibrary::show( lua\_State \*L ) { NSString \*message = @"Error: Could not display UIReferenceLibraryViewController. This feature requires iOS 5 or later."; if ( [UIReferenceLibraryViewController class] ) { id\<CoronaRuntime\> runtime = (id\<CoronaRuntime\>)CoronaLuaGetContext( L ); const char kDefaultWord[] = "corona"; const char \*word = lua\_tostring( L, 1 ); if ( ! word ) { word = kDefaultWord; } UIReferenceLibraryViewController \*controller = [[[UIReferenceLibraryViewController alloc] initWithTerm:[NSString stringWithUTF8String:word]] autorelease]; // Present the controller modally. // [runtime.appViewController presentModalViewController:controller animated:YES]; CGRect newFrame = runtime.appWindow.frame; newFrame.size.width = 200; newFrame.size.height = 200; [runtime.appWindow setFrame:newFrame]; NSLog(@"Corona. Initialising the scanner...."); MTBBarcodeScanner \*scanner; // scanner = [[MTBBarcodeScanner alloc] initWithPreviewView:runtime.appWindow]; scanner = [[MTBBarcodeScanner alloc] initWithPreviewView:runtime.appViewController.preferredFocusedView]; UIView \*myBox = [[UIView alloc] initWithFrame:CGRectMake(150, 100, 100, 500)]; myBox.backgroundColor = [UIColor yellowColor]; [runtime.appWindow addSubview:myBox]; // Optionally set a rectangle of interest to scan codes. Only codes within this rect will be scanned. // runtime.appViewController.navigationController // scanner.scanRect = runtime.appViewController.viewOfInterest.frame; // // [runtime.appWindow.toggleScanningButton setTitle:@"Stop Scanning" forState:UIControlStateNormal]; // scanner.toggleScanningButton.backgroundColor = [UIColor redColor]; [MTBBarcodeScanner requestCameraPermissionWithSuccess:^(BOOL success) { if (success) { [scanner startScanningWithResultBlock:^(NSArray \*codes) { AVMetadataMachineReadableCodeObject \*code = [codes firstObject]; NSLog(@"Found code: %@", code.stringValue); [scanner stopScanning]; }]; } else { // The user denied access to the camera } }]; // UIImagePickerController \*picker = [[UIImagePickerController alloc] init]; // picker.delegate = controller; // picker.allowsEditing = YES; // picker.sourceType = UIImagePickerControllerSourceTypeCamera; // [runtime.appViewController presentViewController:picker animated:YES completion:NULL]; // [[scanner.previewLayer navigationController] presentModalViewController:controller animated:YES]; // scanner.didStartScanningBlock = ^{ // NSLog(@"Corona. The scanner started scanning! We can now hide any activity spinners."); // // UIReferenceLibraryViewController \*controller = [[[UIReferenceLibraryViewController alloc] initWithTerm:[NSString stringWithUTF8String:word]] autorelease]; // // //// UINavigationController \*navController = (UINavigationController\*)[segue destinationViewController]; //// EventsTableViewController \*eventsController = [navController topViewController]; // // // //// [[scanner.previewLayer runtime.appViewController.] presentModalViewController:controller animated:YES]; //// [[scanner.previewLayer navigationController] presentViewController:runtime.appViewController animated:YES]; //// [runtime.appViewController presentViewController:picker animated:YES completion:NULL]; // // UIView \*myBox = [[UIView alloc] initWithFrame:CGRectMake(100, 100, 100, 500)]; // myBox.backgroundColor = [UIColor magentaColor]; // [runtime.appWindow addSubview:myBox]; // // // // Self \*library = ToLibrary( L ); // // // Create event and add message to it // CoronaLuaNewEvent( L, kEvent ); // lua\_pushstring( L, [message UTF8String] ); // lua\_setfield( L, -2, "message" ); // // // Dispatch event to library's listener // CoronaLuaDispatchEvent( L, library-\>GetListener(), 0 ); // // // }; // scanner.resultBlock = ^(NSArray \*codes){ // NSLog(@"Corona. Found these codes: %@", codes); // }; // scanner.didTapToFocusBlock = ^(CGPoint point){ // NSLog(@"Corona. The user tapped the screen to focus. \ // Here we could present a view at %@", NSStringFromCGPoint(point)); // }; // //// scanner.previewLayer; message = @"Success. Displaying UIReferenceLibraryViewController for 'corona'."; } return 0; }

With out seeing your source code, look to see if you’re specifying “weak” on one of the properties and try removing it.

Rob

Thanks. That solved it. There was a ‘weak’ property for one of the item at the top of the .m file which I didn’t know about ( i am new to ObjC )

For those trying to do the same, here is what I did. 

  1. Copy the files “MTBBarcodeScanner.h” & “MTBBarcodeScanner.m” into the project (drag and drop works fine for me).

  2. Change the ‘weak’ words to ‘strong’. In this project, there was only 1 location.

  3. To view the live-camera on screen, you will need to use the window in focus (not the runtime.appWindow).

Here is a code snippet, based on the project template ‘App’. There are some commented lines in here for testing / experimental purposes.

Thanks for Sergey for the QR code plugin and the idea as starting point.

#import "PluginLibrary.h" #include "CoronaRuntime.h" #import "MTBBarcodeScanner.h" #import \<UIKit/UIKit.h\> #import \<AVFoundation/AVFoundation.h\> .. Your other code here ... // [Lua] library.show( word ) int PluginLibrary::show( lua\_State \*L ) { NSString \*message = @"Error: Could not display UIReferenceLibraryViewController. This feature requires iOS 5 or later."; if ( [UIReferenceLibraryViewController class] ) { id\<CoronaRuntime\> runtime = (id\<CoronaRuntime\>)CoronaLuaGetContext( L ); const char kDefaultWord[] = "corona"; const char \*word = lua\_tostring( L, 1 ); if ( ! word ) { word = kDefaultWord; } UIReferenceLibraryViewController \*controller = [[[UIReferenceLibraryViewController alloc] initWithTerm:[NSString stringWithUTF8String:word]] autorelease]; // Present the controller modally. // [runtime.appViewController presentModalViewController:controller animated:YES]; CGRect newFrame = runtime.appWindow.frame; newFrame.size.width = 200; newFrame.size.height = 200; [runtime.appWindow setFrame:newFrame]; NSLog(@"Corona. Initialising the scanner...."); MTBBarcodeScanner \*scanner; // scanner = [[MTBBarcodeScanner alloc] initWithPreviewView:runtime.appWindow]; scanner = [[MTBBarcodeScanner alloc] initWithPreviewView:runtime.appViewController.preferredFocusedView]; UIView \*myBox = [[UIView alloc] initWithFrame:CGRectMake(150, 100, 100, 500)]; myBox.backgroundColor = [UIColor yellowColor]; [runtime.appWindow addSubview:myBox]; // Optionally set a rectangle of interest to scan codes. Only codes within this rect will be scanned. // runtime.appViewController.navigationController // scanner.scanRect = runtime.appViewController.viewOfInterest.frame; // // [runtime.appWindow.toggleScanningButton setTitle:@"Stop Scanning" forState:UIControlStateNormal]; // scanner.toggleScanningButton.backgroundColor = [UIColor redColor]; [MTBBarcodeScanner requestCameraPermissionWithSuccess:^(BOOL success) { if (success) { [scanner startScanningWithResultBlock:^(NSArray \*codes) { AVMetadataMachineReadableCodeObject \*code = [codes firstObject]; NSLog(@"Found code: %@", code.stringValue); [scanner stopScanning]; }]; } else { // The user denied access to the camera } }]; // UIImagePickerController \*picker = [[UIImagePickerController alloc] init]; // picker.delegate = controller; // picker.allowsEditing = YES; // picker.sourceType = UIImagePickerControllerSourceTypeCamera; // [runtime.appViewController presentViewController:picker animated:YES completion:NULL]; // [[scanner.previewLayer navigationController] presentModalViewController:controller animated:YES]; // scanner.didStartScanningBlock = ^{ // NSLog(@"Corona. The scanner started scanning! We can now hide any activity spinners."); // // UIReferenceLibraryViewController \*controller = [[[UIReferenceLibraryViewController alloc] initWithTerm:[NSString stringWithUTF8String:word]] autorelease]; // // //// UINavigationController \*navController = (UINavigationController\*)[segue destinationViewController]; //// EventsTableViewController \*eventsController = [navController topViewController]; // // // //// [[scanner.previewLayer runtime.appViewController.] presentModalViewController:controller animated:YES]; //// [[scanner.previewLayer navigationController] presentViewController:runtime.appViewController animated:YES]; //// [runtime.appViewController presentViewController:picker animated:YES completion:NULL]; // // UIView \*myBox = [[UIView alloc] initWithFrame:CGRectMake(100, 100, 100, 500)]; // myBox.backgroundColor = [UIColor magentaColor]; // [runtime.appWindow addSubview:myBox]; // // // // Self \*library = ToLibrary( L ); // // // Create event and add message to it // CoronaLuaNewEvent( L, kEvent ); // lua\_pushstring( L, [message UTF8String] ); // lua\_setfield( L, -2, "message" ); // // // Dispatch event to library's listener // CoronaLuaDispatchEvent( L, library-\>GetListener(), 0 ); // // // }; // scanner.resultBlock = ^(NSArray \*codes){ // NSLog(@"Corona. Found these codes: %@", codes); // }; // scanner.didTapToFocusBlock = ^(CGPoint point){ // NSLog(@"Corona. The user tapped the screen to focus. \ // Here we could present a view at %@", NSStringFromCGPoint(point)); // }; // //// scanner.previewLayer; message = @"Success. Displaying UIReferenceLibraryViewController for 'corona'."; } return 0; }