I am currently working on a project and using tesseract API .
The code is following :
UIImage *bwImage = [image g8_blackAndWhite];
[self.activityIndicator startAnimating];
// Display the preprocessed image to be recognized in the view
self.imageView.image = bwImage;
G8RecognitionOperation *operation = [[G8RecognitionOperation alloc] init];
operation.tesseract.engineMode = G8OCREngineModeTesseractOnly;
operation.tesseract.pageSegmentationMode = G8PageSegmentationModeAutoOnly;
operation.delegate = self;
operation.recognitionCompleteBlock = ^(G8Tesseract *tesseract) {
// Fetch the recognized text
NSString *recognizedText = tesseract.recognizedText;
NSLog(#"%#", recognizedText);
[self.activityIndicator stopAnimating];
// Spawn an alert with the recognized text
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"OCR Result"
message:recognizedText
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alert show];
};
//NSLog(#"%#",);
// Finally, add the recognition operation to the queue
[self.operationQueue addOperation:operation];
}
I want to pass recognizedText string to second View controller but it is not visible outside the block.
How can I achieve this, any advice?
Declare recognizedText outside block with __block keyword to make it visible outside block.
Like below code:
......
__block NSString *recognizedText;//declared outside to make it visible outside block
operation.recognitionCompleteBlock = ^(G8Tesseract *tesseract) {
// Fetch the recognized text
recognizedText = tesseract.recognizedText;
NSLog(#"%#", recognizedText);
[self.activityIndicator stopAnimating];
// Spawn an alert with the recognized text
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"OCR Result"
message:recognizedText
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alert show];
};
......
Related
Hi I have an video recored output and i want to parse it to the other controller using either blocks or nsnotification center. Here is the code used to get output.
- (void)saveRecordedFile:(NSURL *)recordedFile {
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_async(queue, ^{
ALAssetsLibrary *assetLibrary = [[ALAssetsLibrary alloc] init];
[assetLibrary writeVideoAtPathToSavedPhotosAlbum:recordedFile
completionBlock:
^(NSURL *assetURL, NSError *error) {
dispatch_async(dispatch_get_main_queue(), ^{
NSString *title;
NSString *message;
if (error != nil) {
title = #"Failed to save video";
message = [error localizedDescription];
}
else {
title = #"Saved!";
message = nil;
}
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title
message:message
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alert show];
NSLog(#"%#",recordedFile);'
//
}
This output i have to pass to next view controller and from this to time line same like instagram app.
one more thing is already collection view is having images
some body please help me to solve this problem
I simply trying to add my passbook without sharing via email. How i can add my passbook on click button?
This code assumes that you know how to create the pass in the first place...
NSError * passerror;
PKPass * pass = [[PKPass alloc] initWithData:data error:&passerror];
if(!pass) {
UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:#"Pass Failed" message:#"Sorry there was a problem creating your Passbook." delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alertView show];
return;
}
//init a pass library
PKPassLibrary* passLib = [[PKPassLibrary alloc] init];
//check if pass library contains this pass already
if([passLib containsPass:pass]) {
//pass already exists in library, show an error message
UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:#"Pass Exists" message:#"Pass is already in Passbook." delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alertView show];
} else {
//present view controller to add the pass to the library
PKAddPassesViewController *vc = [[PKAddPassesViewController alloc] initWithPass:pass];
[vc setDelegate:(id)self];
[self presentViewController:vc animated:YES completion:nil];
}
EDIT You'll need to import
#import <PassKit/PassKit.h>
I have a very simply method. However in the method the UIAlertView will not run.... Here is my method:
-(void)post_result {
NSLog(#"Post Result");
post_now.enabled = YES;
[active stopAnimating];
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"Success" message:#"You're post has been successfully uploaded." delegate:self cancelButtonTitle:#"Dismiss" otherButtonTitles:nil];
[alertView show];
success_post_facebook = 0;
success_post_youtube = 0;
success_post_googleplus = 0;
success_post_tumblr = 0;
success_post_twitter = 0;
NSLog(#"Post Result END");
}
The odd thing is that the code before and after the UIAlertView will run in this method.... So what an earth is wrong??
Thanks for your time.
Your are most likely calling that UIAlertView not on the main thread. To make it run on the main thread just use the main dispatch queue like so.
dispatch_async(dispatch_get_main_queue(), ^{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"Success" message:#"You're post has been successfully uploaded." delegate:self cancelButtonTitle:#"Dismiss" otherButtonTitles:nil];
[alertView show];
});
In the box api there's a button to make a folder. But i can't figure out how to modify the button to let me make a folder with subfolders included.
what im trying to make:
When you click the Add folder button you get a NSAlert which asks you what name you want to give it. This alert must be modified so it has multiple text bars. In the first bar you can fill in the new folders name. the other (3) you can leave blank for creating no subfolders, or fill in a name to create a subfolder.
Is this possible? I would appreciate every help or hint you can give me!
some code:
#pragma mark - Folder creation - (void)addFolderButtonClicked:(id)sender { UIAlertView *folderNamePrompt = [[UIAlertView alloc] initWithTitle:#"Add Folder" message:#"Name:" delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles:#"OK", nil];
folderNamePrompt.alertViewStyle = UIAlertViewStylePlainTextInput;
[folderNamePrompt show];
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{ if (buttonIndex == alertView.firstOtherButtonIndex) { UITextField *nameField = [alertView textFieldAtIndex:0]; BoxFolderBlock success = ^(BoxFolder *folder) { [self fetchFolderItemsWithFolderID:self.folderID name:self.navigationItem.title]; };
BoxAPIJSONFailureBlock failure = ^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, NSDictionary *JSONDictionary)
{
NSLog(#"folder create failed with error code: %i", response.statusCode);
if (response.statusCode == 409)
{
dispatch_sync(dispatch_get_main_queue(), ^{
UIAlertView *conflictAlert = [[UIAlertView alloc] initWithTitle:#"Name conflict" message:[NSString stringWithFormat:#"A folder already exists with the name %#.\n\nNew name:", nameField.text] delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles:#"OK", nil];
conflictAlert.alertViewStyle = UIAlertViewStylePlainTextInput;
[conflictAlert show];
});
}
};
BoxFoldersRequestBuilder *builder = [[BoxFoldersRequestBuilder alloc] init];
builder.name = nameField.text;
builder.parentID = self.folderID;
[[BoxSDK sharedSDK].foldersManager createFolderWithRequestBuilder:builder success:success failure:failure];
}
I want to share a photo from the Internet to WECHAT, but after I press the share button , nothing happens , I am new to Objective-C and I am unable to figure out the problem myself.Hearing that there are a lot of experts here,so is there some guy can help me solve this one? thanks in advance. here are the codes:
UIImage * image = [[[imageTitleArray objectAtIndex:initIndex] albumImageView] image];
WXMediaMessage *message = [WXMediaMessage message];
[message setThumbImage: image];
WXImageObject *ext = [WXImageObject object];
ext.imageData = UIImageJPEGRepresentation(image,1);
message.mediaObject = ext;
SendMessageToWXReq* req = [[[SendMessageToWXReq alloc] init]autorelease];
req.bText = NO;
req.message = message;
[WXApi sendReq:req];
Try the following method
- (void) sendImageContentToWeixin:(UIImage *)image {
//if the Weixin app is not installed, show an error
if (![WXApi isWXAppInstalled]) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:#"The Weixin app is not installed" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles: nil];
[alert show];
return;
}
//create a message object
WXMediaMessage *message = [WXMediaMessage message];
//set the thumbnail image. This MUST be less than 32kb, or sendReq may return NO.
//we'll just use the full image resized to 100x100 pixels for now
[message setThumbImage:[image resizedImage:CGSizeMake(100,100) interpolationQuality:kCGInterpolationDefault]];
//create an image object and set the image data as a JPG representation of our UIImage
WXImageObject *ext = [WXImageObject object];
ext.imageData = UIImageJPEGRepresentation(image, 0.8);
message.mediaObject = ext;
//create a request
SendMessageToWXReq* req = [[SendMessageToWXReq alloc] init];
//this is a multimedia message, not a text message
req.bText = NO;
//set the message
req.message = message;
//set the "scene", WXSceneTimeline is for "moments". WXSceneSession allows the user to send a message to friends
req.scene = WXSceneTimeline;
//try to send the request
if (![WXApi sendReq:req]) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:#"Error" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles: nil];
[alert show];
}
}