I am trying to implement some qr code reader using ZBar.
After a while I did manage to do reading, but after several readings the app tends to get slower and slower (until practically unresponsive).
This SDK is compatible with iOS7 ?
Frameworks : libiconv.dylib,libinfo.dylib, QuartzCore, CoreVideo,CoreMedia,AVFoundation,CoreGraphics,UIKit,XCTest
- (IBAction)scan:(id)sender {
//initialize the reader and provide some config instructions
ZBarReaderViewController *reader = [ZBarReaderViewController new];
reader.readerDelegate = self;
[reader.scanner setSymbology: ZBAR_I25
config: ZBAR_CFG_ENABLE
to: 1];
reader.cameraFlashMode=UIImagePickerControllerCameraFlashModeOff;
reader.readerView.zoom = 1.0; // define camera zoom property
//show the scanning/camera mode
[self presentModalViewController:reader animated:YES];
// Do any additional setup after loading the view from its nib.
}
- (void) imagePickerController: (UIImagePickerController*) reader
didFinishPickingMediaWithInfo: (NSDictionary*) info {
//this contains your result from the scan
id results = [info objectForKey: ZBarReaderControllerResults];
//create a symbol object to attach the response data to
ZBarSymbol *symbol = nil;
//add the symbol properties from the result
//so you can access it
for(symbol in results){
//symbol.data holds the value
NSString *upcString = symbol.data;
//print to the console
NSLog(#"the value of the scanned UPC is: %#",upcString);
NSMutableString *message = [[NSMutableString alloc]
initWithString: #"Scanned Barcode: "];
[message appendString:[NSString stringWithFormat:#"%# ",
upcString]];
//Create UIAlertView alert
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:#"Product Barcode" message: message delegate:self
cancelButtonTitle:#"Cancel" otherButtonTitles: nil];
self.viewResult.text = upcString;
[alert show];
//After some time
[alert dismissWithClickedButtonIndex:0 animated:TRUE];
//make the reader view go away
[reader dismissModalViewControllerAnimated: YES];
}
}
EDIT : After 4 or 5 readings, this is the memory and CPU consumption -> http://diogomend.me/images/capt.png. Christ :D
Well, after checking this issue Memory related issue of ZBarReaderViewController in iOS 7, I did manage to solve the problem.
The lines I've added are the following:
(in my viewcontroller.h)
#property (strong,nonatomic) ZBarReaderViewController *reader;
(in my viewcontroller.m)
if(self.reader)
{
[self.reader.readerView stop];
for(UIView *subViews in self.reader.view.subviews)
[subViews removeFromSuperview];
[self.reader.view removeFromSuperview];
self.reader.view = nil;
}
_reader = [ZBarReaderViewController new];
Related
Integrated Paytm sdk 2.1 in iOS (Xcode 7) and configured to make payment .
I have a form in which amount and other fields need to filled then there is a button for Payment .
Here is code which i am using :
//Step 1: Create a default merchant config object
PGMerchantConfiguration *mc = [PGMerchantConfiguration defaultConfiguration];
//Step 2: If you have your own checksum generation and validation url set this here. Otherwise use the default Paytm urls
mc.checksumGenerationURL = #"generate checksum url";
mc.checksumValidationURL = #"checksum validation url";
//Step 3: Create the order with whatever params you want to add. But make sure that you include the merchant mandatory params
NSMutableDictionary *orderDict = [NSMutableDictionary new];
//Merchant configuration in the order object
orderDict[#"MID"] = #"abc1111";
orderDict[#"CHANNEL_ID"] = #"WAP";
orderDict[#"INDUSTRY_TYPE_ID"] = #"Education";
orderDict[#"WEBSITE"] = #"companyname";
//Order configuration in the order object
orderDict[#"TXN_AMOUNT"] = #"100";
orderDict[#"ORDER_ID"] = [Feepayment generateOrderIDWithPrefix:#"111"];
orderDict[#"REQUEST_TYPE"] = #"DEFAULT";
orderDict[#"CUST_ID"] = #"abc7777";
PGOrder *order = [PGOrder orderWithParams:orderDict];
//Step 4: Choose the PG server. In your production build dont call selectServerDialog. Just create a instance of the
//PGTransactionViewController and set the serverType to eServerTypeProduction
[PGServerEnvironment selectServerDialog:self.view completionHandler:^(ServerType type)
{
PGTransactionViewController *txnController = [[PGTransactionViewController alloc] initTransactionForOrder:order];
//show title var
UIView *mNavBar = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width,44)];
mNavBar.backgroundColor = [UIColor grayColor];
txnController.topBar = mNavBar;
//Cancel button
UIButton *mCancelButton = [[UIButton alloc] initWithFrame:CGRectMake(5, 2, 70, 40)];
[mCancelButton setTitle:#"Cancel" forState:UIControlStateNormal];
mCancelButton.titleLabel.textColor = PURPLE_COLOR;
[mCancelButton setFont:[UIFont fontWithName:#"Helvetica-Bold" size:15.0]];
txnController.cancelButton = mCancelButton;
//add title
UILabel *mTitleLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.view.frame.size.width/2 - 10, 1, 100, 50)];
[mTitleLabel setText:#"Payment"];
[mTitleLabel setFont:[UIFont fontWithName:#"Helvetica-Bold" size:15.0]];
mTitleLabel.textColor = [UIColor whiteColor];
[mNavBar addSubview:mTitleLabel];
if (type!=eServerTypeNone) {
txnController.serverType = type;
txnController.merchant = mc;
txnController.loggingEnabled = YES;
txnController.sendAllChecksumResponseParamsToPG = YES;
txnController.delegate = self;
[self showController:txnController];
}
}];
//show controller method
-(void)showController:(PGTransactionViewController *)controller {
if (self.navigationController != nil)
[self.navigationController pushViewController:controller animated:YES];
else
[self presentViewController:controller animated:YES
completion:^{
}];
}
//remove controller
-(void)removeController:(PGTransactionViewController *)controller {
if (self.navigationController != nil)
[self.navigationController popViewControllerAnimated:YES];
else
[controller dismissViewControllerAnimated:YES
completion:^{
}];
}
#pragma mark PGTransactionViewController delegate
- (void)didSucceedTransaction:(PGTransactionViewController *)controller
response:(NSDictionary *)response {
DEBUGLOG(#"ViewController::didSucceedTransactionresponse= %#", response);
NSString *title = [NSString stringWithFormat:#"Your order was completed successfully. \n %#", response[#"ORDERID"]];
[[[UIAlertView alloc] initWithTitle:title message:[response description] delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil] show];
[self removeController:controller];
}
- (void)didFailTransaction:(PGTransactionViewController *)controller error:(NSError *)error response:(NSDictionary *)response {
DEBUGLOG(#"ViewController::didFailTransaction error = %# response= %#", error, response);
if (response)
{
[[[UIAlertView alloc] initWithTitle:error.localizedDescription message:[response description] delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil] show];
}
else if (error)
{
[[[UIAlertView alloc] initWithTitle:#"Error" message:error.localizedDescription delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil] show];
}
[self removeController:controller];
}
- (void)didCancelTransaction:(PGTransactionViewController *)controller error:(NSError*)error response:(NSDictionary *)response {
DEBUGLOG(#"ViewController::didCancelTransaction error = %# response= %#", error, response);
NSString *msg = nil;
if (!error) msg = [NSString stringWithFormat:#"Successful"];
else msg = [NSString stringWithFormat:#"UnSuccessful"];
[[[UIAlertView alloc] initWithTitle:#"Transaction Cancel" message:msg delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil] show];
[self removeController:controller];
}
- (void)didFinishCASTransaction:(PGTransactionViewController *)controller response:(NSDictionary *)response {
DEBUGLOG(#"ViewController::didFinishCASTransaction:response = %#", response);
}
Here is screenshot while using staging directly showing this page :
*Note - Actually i am trying for staging not for production .
When i execute then it doesnt showing Paytm feepayment form instead it showing orderid and amount with transaction id dirctly .
How to open Paytm payment form when user enter fee amount in the form then it should calcualte the amount with extraa tax and then clicking on Fee payment button it should open PAYTM PAYMENT FORM.
PLEASE HELP ME TO SOLVE THIS PROBLEM ( I HAVE GO THROUGH THE PAYTM SDK DOC STEP BY STEP BUT DINT ABLE TO FIND IT ).
THANKS.
Important : **As far as checksumGenerationURL and checksumValidationURL is concerned , we need to create it . Initially i tried to use from Paytm but it dint work so finally our server team did it , this is most important point for Integrating Paytm
Finally , Solved by testing it on the Production and its working fine . As far as Staging server is concerned i guess there is hard coded information is in the sdk so hope in the next version of PGSDK we could test it on Staging too.
Thanks .
#Pradeep k ... thank you very much for all your valuable support .
Have you populated the mc.checksumGenerationURL and mc.checksumValidationURL properly? Also there is a 2.7 version of the SDK that you should be using. Ask your Paytm contact point for the latest iOS SDK.
Now about the amount, Paytm does not calculate the tax. You have to add it to the amount that you are sending to Paytm.
I am writing an app, which is getting data from the net using XML. It is a master-detail-app which is fetching data for the master-table and after selecting one item from the master-Table it fills the data for the detailview(s) using another network-access.
I would like to present an alert in order to show the user that the app is busy accessing the net or busy calculating. So I would present the view from the UIAlertController before the calculation / network access starts and dismiss the view when the activity has completed
Problem is: I don't know where to put this call to show / dismiss the UIAlertcontroller view.
Putting the activity code into ViewWillAppear shows and dismisses the alertview BEFORE the network-access... Putting everything into ViewDidLoad seems not the way to go.
- (void) viewWillAppear:(BOOL)animated
{
UIAlertController *alert = [UIAlertController alertControllerWithTitle:#"Working"
message:#"Working on it"
preferredStyle:UIAlertControllerStyleAlert];
self.objects = [[NSMutableArray alloc] init];
self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:#"Accounts"
style:UIBarButtonItemStylePlain
target:nil
action:nil];
NSURL *url;
if ([self getSession])
{
NSMutableString *URLstring = [NSMutableString stringWithString:#"https://XXXXXXXXXXXXXXX.xml?session="];
[self presentViewController:alert animated:YES completion:nil];
[URLstring appendString:[[DataStore getData]SessionString]];
url = [NSURL URLWithString:URLstring];
self.myXXXXXXParserAlleKontenXMLDelegate = [[KontenParserDelegate alloc] init];
self.xmlParser = [[NSXMLParser alloc] initWithContentsOfURL:url];
self.xmlParser.delegate = self.myfxbookParserAlleKontenXMLDelegate;
if ([self.xmlParser parse])
{
[self.objects removeAllObjects];
for(int i=0; i< [self.XXXXXXXXXrAlleKontenXMLDelegate.allAccounts count];i++)
{
[self.objects addObject : [self.myfxbookParserAlleKontenXMLDelegate.allAccounts objectAtIndex:i]];
}
NSSortDescriptor *sort = [[NSSortDescriptor alloc] initWithKey: #"name" ascending: YES];
[self.objects sortUsingDescriptors:#[sort]];
[self.tableView reloadData];
[self dismissViewControllerAnimated:YES completion:nil];
// Do any additional setup after loading the view, typically from a nib.
}
}
}
Added After some discussions I added some new framework "SVProgressHUD" and entered the following code into "ViewWillAppear" where [self parserstuff] contains all the XML parsing..
[SVProgressHUD show];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
[self parserstuff];
dispatch_async(dispatch_get_main_queue(), ^{
[SVProgressHUD dismiss];
});
});
This leaves me with a HUD-Display showing up while parsing XML but the resulting Tableview does not show data but is empty... After switching to DISPATCH_SYNC it works.
Solution would be
1) Put code in ViewDidLoad
2) encapsulate Code between "SVProgressHUD show" and "dismiss" with dispatch_async
as in
dispatch_async(dispatch_get_main_queue(), ^{
[SVProgressHUD show];
[self parserstuff];
[self fillComparatorParameters:nil];
[self.tableView reloadData];
[SVProgressHUD dismiss];
// }];
});
My project will save data to parse and while I can pick an image from my library I cannot open the camera. I found a tutorial to do this but it is not compatible with my code. The link to the tutorial is here: Tutorial . I am using .storyboard and the tutorial is .xib, I do not know if this will change anything.
my .m file is here:
#import "NewRecipeViewController.h"
#import <MobileCoreServices/UTCoreTypes.h>
#import <Parse/Parse.h>
#import "MBProgressHUD.h"
#interface NewRecipeViewController ()
- (IBAction)save:(id)sender;
- (IBAction)cancel:(id)sender;
#property (weak, nonatomic) IBOutlet UIImageView *recipeImageView;
#property (weak, nonatomic) IBOutlet UITextField *nameTextField;
#property (weak, nonatomic) IBOutlet UITextField *prepTimeTextField;
#property (weak, nonatomic) IBOutlet UITextField *ingredientsTextField;
#end
#implementation NewRecipeViewController
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
_nameTextField.delegate = self;
_prepTimeTextField.delegate = self;
_ingredientsTextField.delegate = self;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.row == 0) {
[self showPhotoLibary];
}
}
- (void)showPhotoLibary
{
if (([UIImagePickerController isSourceTypeAvailable:
UIImagePickerControllerSourceTypeSavedPhotosAlbum] == NO)) {
return;
}
UIImagePickerController *mediaUI = [[UIImagePickerController alloc] init];
mediaUI.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
// Displays saved pictures from the Camera Roll album.
mediaUI.mediaTypes = #[(NSString*)kUTTypeImage];
// Hides the controls for moving & scaling pictures
mediaUI.allowsEditing = NO;
mediaUI.delegate = self;
[self.navigationController presentModalViewController: mediaUI animated: YES];
}
- (IBAction)save:(id)sender {
// Create PFObject with recipe information
PFObject *recipe = [PFObject objectWithClassName:#"Recipe"];
[recipe setObject:_nameTextField.text forKey:#"name"];
[recipe setObject:_prepTimeTextField.text forKey:#"prepTime"];
NSArray *ingredients = [_ingredientsTextField.text componentsSeparatedByString: #","];
[recipe setObject:ingredients forKey:#"ingredients"];
// Recipe image
NSData *imageData = UIImageJPEGRepresentation(_recipeImageView.image, 0.8);
NSString *filename = [NSString stringWithFormat:#"%#.png", _nameTextField.text];
PFFile *imageFile = [PFFile fileWithName:filename data:imageData];
[recipe setObject:imageFile forKey:#"imageFile"];
// Show progress
MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
hud.mode = MBProgressHUDModeIndeterminate;
hud.labelText = #"Uploading";
[hud show:YES];
// Upload recipe to Parse
[recipe saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
[hud hide:YES];
if (!error) {
// Show success message
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Upload Complete" message:#"Successfully saved the recipe" delegate:Nil cancelButtonTitle:#"OK" otherButtonTitles:nil, nil];
[alert show];
// Notify table view to reload the recipes from Parse cloud
[[NSNotificationCenter defaultCenter] postNotificationName:#"refreshTable" object:self];
// Dismiss the controller
[self dismissViewControllerAnimated:YES completion:nil];
} else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Upload Failure" message:[error localizedDescription] delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil, nil];
[alert show];
}
}];
}
- (IBAction)cancel:(id)sender {
[self dismissViewControllerAnimated:YES completion:nil];
}
- (void)viewDidUnload {
[self setRecipeImageView:nil];
[self setNameTextField:nil];
[self setPrepTimeTextField:nil];
[self setIngredientsTextField:nil];
[super viewDidUnload];
}
- (void) imagePickerController: (UIImagePickerController *) picker didFinishPickingMediaWithInfo: (NSDictionary *) info {
UIImage *originalImage = (UIImage *) [info objectForKey:UIImagePickerControllerOriginalImage];
self.recipeImageView.image = originalImage;
[picker dismissViewControllerAnimated:YES completion:nil];
}
#pragma mark - Textfield delegate
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
[textField resignFirstResponder];
return YES;
}
- (IBAction)takephoto:(id)sender {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentViewController:picker animated:YES completion:NULL];
}
- (IBAction)selectphoto:(id)sender {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController:picker animated:YES completion:NULL];
}
#end
Any help is appreciated.
Take a look at Apple's provided sample project (especially APLViewController.m)
https://developer.apple.com/library/ios/samplecode/PhotoPicker/Introduction/Intro.html#//apple_ref/doc/uid/DTS40010196
You'll see them do the following 4 steps. You are only doing the last half of step one, without first verifying if that source type is even available.
From the UIImagePickerController Class Reference:
To use an image picker controller containing its default controls, perform these steps:
Verify that the device is capable of picking content from the desired source. Do this calling the isSourceTypeAvailable: class method, providing a constant from the “UIImagePickerControllerSourceType” enumeration.
Check which media types are available, for the source type you’re using, by calling the availableMediaTypesForSourceType: class method. This lets you distinguish between a camera that can be used for video recording and one that can be used only for still images.
Tell the image picker controller to adjust the UI according to the media types you want to make available—still images, movies, or both—by setting the mediaTypes property.
Present the user interface. On iPhone or iPod touch, do this modally (full-screen) by calling the presentViewController:animated:completion: method of the currently active view controller, passing your configured image picker controller as the new view controller.
I use ZBarReaderViewController for scan QR Code. and it was perfectly worked on iOS 6.
But when i use iOS 7 with my project then it is not properly working with ZBarReaderViewController
Issue is related to memory, it take more then 100 MB and my device is hang at this time.
Generally in my project. user can scan QR Generator image and i have function which recognize code of QR code is related to my string which i got from server then if YES then i goes to next view controller otherwise remain in current (continue QR SCAN) screen.
If QR code mach with my string then on next screen has "cancel" button which make be scan another code ( it means i got to previous viewController (QR SCAN)).
At that time when i go to next viewController and back to pervious (QR Scan screen) then each time i got ZBarReaderViewController is allocated so (May be) memory related issue is generated.
but i write code
if(self.ZBarReaderVC)
{
for(UIView *subVies in self.ZBarReaderVC.cameraOverlayView.subviews)
[subVies removeFromSuperview];
for(UIView *subVies in self.ZBarReaderVC.view.subviews)
[subVies removeFromSuperview];
[self.ZBarReaderVC removeFromParentViewController];
self.ZBarReaderVC = nil;
}
after [self.ZBarReaderVC dismissModalViewControllerAnimated: YES]; I remove ZBarReaderViewController at the end time then why each time i got allocated ZBarReaderViewController ???
And also i put [self.ZBarReaderVC.readerView stop]; before dismiss ZBarReaderViewController fro stop scanning stream of reader
but also it not worked for me.
But i tried to solve my problem about hours of time but i am not able to solve my issue
please help me.
Alos i found similar problem
Zbar SDK and ios7/xcode 5 - App is reaching 100% cpu use and memory more than 100MB
http://sourceforge.net/p/zbar/discussion/1072195/thread/df4c215a/
But No one can help me.
I found that in iOS 7 issue is occur at
self.ZBarReaderVC.view.frame = self.view.bounds;
I put break point here and check whenever i come bake from previous viewController, its take more time and also memory (issue) at this code.
So first i need to remove view of self.ZBarReaderVC with its all subViews.. so at first i need to write
if(self.ZBarReaderVC) // first check `self.ZBarReaderVC` is created or not?
{
[self.ZBarReaderVC.readerView stop]; // then stop continue scanning stream of "self.ZBarReaderVC"
for(UIView *subViews in self.ZBarReaderVC.view.subviews) // remove all subviews
[subViews removeFromSuperview];
[self.ZBarReaderVC.view removeFromSuperview];
self.ZBarReaderVC.view = nil;
}
And also i got that in iOS 7 self.ZBarReaderVC has remain continue scanning stream of QR Code so each time we need to stop it whenever your QR Code scanning is done and you need to dismiss your self.ZBarReaderVC then first stop scanning by [self.ZBarReaderVC.readerView stop];
And some time user need to write/call (For do/implement some type of extra features)
[self.ZBarReaderVC viewDidLoad];
[self.ZBarReaderVC viewWillAppear:NO];
[self.ZBarReaderVC viewDidAppear:NO];
Methods of self.ZBarReaderVC then it is not need to use in iOS 7, so if any user who call this methods of self.ZBarReaderVC then please put it in comment.
I hope this my suggestion is helpful for others.
Thanks :)
If you are targetting your app for iOS7 only, I ditched the ZBar component and used the native AVFoundation method, making the viewcontroller a AVCaptureMetadataOutputObjectsDelegate. Works prefectly with 3% CPU usage:
viewcontroller.h:
#interface viewcontroller : UIViewController <AVCaptureMetadataOutputObjectsDelegate> {
AVCaptureSession *_session;
AVCaptureDevice *_device;
AVCaptureDeviceInput *_input;
AVCaptureMetadataOutput *_output;
AVCaptureVideoPreviewLayer *_prevLayer;
UIView *_highlightView;
}
viewcontroller.m
- (IBAction)btnScan:(id)sender {
_session = [[AVCaptureSession alloc] init];
_device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
NSError *error = nil;
_input = [AVCaptureDeviceInput deviceInputWithDevice:_device error:&error];
if (_input) {
[_session addInput:_input];
} else {
NSLog(#"Error: %#", error);
}
_output = [[AVCaptureMetadataOutput alloc] init];
[_output setMetadataObjectsDelegate:self queue:dispatch_get_main_queue()];
[_session addOutput:_output];
_output.metadataObjectTypes = [_output availableMetadataObjectTypes];
_prevLayer = [AVCaptureVideoPreviewLayer layerWithSession:_session];
_prevLayer.frame = self.view.bounds;
_prevLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;
[self.view.layer addSublayer:_prevLayer];
[_session startRunning];
}
- (void)captureOutput:(AVCaptureOutput *)captureOutput
didOutputMetadataObjects:(NSArray *)metadataObjects
fromConnection:(AVCaptureConnection *)connection {
AVMetadataMachineReadableCodeObject *barCodeObject;
NSString *detectionString = nil;
NSArray *barCodeTypes = #[AVMetadataObjectTypeCode39Code, AVMetadataObjectTypeCode128Code,
AVMetadataObjectTypeQRCode];
for (AVMetadataObject *metadata in metadataObjects) {
for (NSString *type in barCodeTypes) {
if ([metadata.type isEqualToString:type]) {
barCodeObject = (AVMetadataMachineReadableCodeObject *)
[_prevLayer transformedMetadataObjectForMetadataObject:
(AVMetadataMachineReadableCodeObject *)metadata];
detectionString = [(AVMetadataMachineReadableCodeObject *)metadata stringValue];
break;
}
}
if (detectionString != nil) {
NSLog(#"%#", detectionString);
[self buscarCarga:detectionString]; //Do whatever you want with the data
[_session stopRunning];
AVCaptureInput* input = [_session.inputs objectAtIndex:0];
[_session removeInput:input];
AVCaptureVideoDataOutput* output = (AVCaptureVideoDataOutput*)[_session.outputs objectAtIndex:0];
[_session removeOutput:output];
[_prevLayer removeFromSuperlayer];
}
else
NSLog(#"No data");
}
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.ZBarReaderVC = [ZBarReaderViewController new];
self.ZBarReaderVC.readerDelegate=self;
self.ZBarReaderVC.supportedOrientationsMask = ZBarOrientationMaskAll;
ZBarImageScanner *scanner = self.ZBarReaderVC.scanner;
[scanner setSymbology: ZBAR_I25 config: ZBAR_CFG_ENABLE to: 0];
}
#pragma mark - Button click method
- (IBAction)startScanning:(id)sender {
NSLog(#"Scanning..");
resultTextView.text = #"Scanning..";
[self presentViewController:self.ZBarReaderVC animated:YES completion:nil];
}
I am currently developing an iPhone app that makes use of a UIImagePickerController with a custom overlay to take photos.
Unfortunately I do not have direct access to an iPhone 4S but several testers have reported that the camera picker is drawing a green border around faces exactly like this: http://cdn.iphonehacks.com/wp-content/uploads/2012/03/camera_faces.jpg
Due to the nature of this app this is not desirable.
A thorough search of the UIImagePickerController docs didn't turn up anything and similarly everything I could find on here relating to face detection was providing instructions in how to use a CIDetector or similar.
How can I disable face detection in my UIImagePickerController?
Here is my initialisation code for the UIImagePickerController:
UIImagePickerController *cameraPicker = [[UIImagePickerController alloc] init];
[cameraPicker setSourceType:UIImagePickerControllerSourceTypeCamera];
[cameraPicker setCameraDevice:UIImagePickerControllerCameraDeviceRear];
if ([UIImagePickerController isFlashAvailableForCameraDevice:cameraPicker.cameraDevice]){
[cameraPicker setCameraFlashMode:UIImagePickerControllerCameraFlashModeOn];
}
[cameraPicker setShowsCameraControls:NO];
[cameraPicker setCameraOverlayView:cameraOverlayView];
cameraPicker.delegate = self;
[self presentModalViewController:cameraPicker animated:YES];
Try This -->
Lets Say We have one UIViewController named as - RecordVideoViewController
Implementation of -- RecordVideoViewController.h
#import <UIKit/UIKit.h>
#import <MediaPlayer/MediaPlayer.h>
#import <MobileCoreServices/UTCoreTypes.h>
#import <AssetsLibrary/AssetsLibrary.h>
#interface RecordVideoViewController : UIViewController
- (IBAction)recordAndPlay:(id)sender;
-(BOOL)startCameraControllerFromViewController:(UIViewController*)controllerusingDelegate:
(id)delegate;
-(void)video:(NSString *)videoPath didFinishSavingWithError:(NSError *)error
contextInfo(void*)contextInfo;
#end
Implementation of -- RecordVideoViewController.m
- (IBAction)recordAndPlay:(id)sender {
[self startCameraControllerFromViewController:self usingDelegate:self];
}
-(BOOL)startCameraControllerFromViewController:(UIViewController*)controller
usingDelegate:(id )delegate
{
// 1 - Validattions
if (([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera] ==
NO)
|| (delegate == nil)
|| (controller == nil)) {
return NO;
}
// 2 - Get image picker
UIImagePickerController *cameraUI = [[UIImagePickerController alloc] init];
cameraUI.sourceType = UIImagePickerControllerSourceTypeCamera;
// Displays a control that allows the user to choose movie capture
cameraUI.mediaTypes = [[NSArray alloc] initWithObjects:(NSString *)kUTTypeMovie, nil];
// Hides the controls for moving & scaling pictures, or for
// trimming movies. To instead show the controls, use YES.
cameraUI.allowsEditing = NO;
cameraUI.delegate = delegate;
// 3 - Display image picker
[controller presentViewController:cameraUI animated:YES completion:nil];
return YES;
}
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:
(NSDictionary *)info {
NSString *mediaType = [info objectForKey: UIImagePickerControllerMediaType];
[self dismissViewControllerAnimated:YES completion:nil];
// Handle a movie capture
if (CFStringCompare ((__bridge_retained CFStringRef) mediaType, kUTTypeMovie, 0) ==
kCFCompareEqualTo) {
NSString *moviePath = [[info objectForKey:UIImagePickerControllerMediaURL] path];
if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(moviePath)) {
UISaveVideoAtPathToSavedPhotosAlbum(moviePath,
self,#selector(video:didFinishSavingWithError:contextInfo:),nil);
}
}
}
-(void)video:(NSString*)videoPath didFinishSavingWithError:(NSError*)error contextInfo:
(void*)contextInfo {
if (error) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Error" message:#"Video Saving
Failed"
delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
} else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Video Saved" message:#"Saved To
Photo Album" delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
}
}
Implement This code it, i hope this will help you .
Check out this post. There are some hints here, but still can't find much info outside of Apple's docs on this API.
Proper usage of CIDetectorTracking