iPhone Abbyy OCR - ios

I'm working on an iphone app that uses Abbyy OCR.
Using the wrapper class for iphone there is a method :
[ocrManager recognizeImage:[choosenImage image] withCallback:self];
a UIImage is passed as a parameter which is used to recognize characters. But every time i receive exception "Required Data File Missed".
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
[picker dismissModalViewControllerAnimated:YES];
[[UIApplication sharedApplication] setStatusBarHidden:NO];
if(check == 1)
{
return;
}
check = 1;
UIImage *image = [info objectForKey:#"UIImagePickerControllerOriginalImage"];
[choosenImage setImage:image];
[process setHidden:NO];
NSString *filePath = [[NSBundle mainBundle] pathForResource:#"license" ofType:#""];
NSData *license = [[NSData alloc] initWithContentsOfFile:filePath];
CMocrManager *ocrManager = [CMocrManager createManager:license];
NSSet *languages = [[NSSet alloc] initWithArray:[NSArray arrayWithObject:#"English"]];
[ocrManager setLanguages:languages];
[ocrManager setDefaultImageResolution:0];
#try {
[ocrManager recognizeImage:[choosenImage image] withCallback:self];
}
#catch (NSException *exception) {
NSString *ex = exception.reason;
}
CMocrLayout* recognitionResult = [ocrManager copyRecognitionResults];
NSArray* strings = [recognitionResult copyStrings];
}
the image can be seen on UIImageView but when I pass it to recognizeImage method it throws the exception.
I've been researching a lot but unable to find a solution. Any help is appreciated.

My name is Nikolay Khlebinsky, i work # ABBYY.
"Required Data File Missed" error message is displayed when resource files are missing (keywords, patterns or dictionaries). Refer to «How to Work with the ABBYY Mobile OCR Engine Library on the iPhone» help article for project organization guide. You can also look for iPhone project sample in the engine distributive.
If you would still experience any difficulties, please visit our technical support contacts page at http://www.abbyy.com/support/contacts/ Choose your country and your product, hit 'Search' and you'll get contacts of the proper ABBYY representatives. Contacting them is the fastest way to solve technical issues.

Related

Integrating(Using) iCloud in iOS Apps?

I have simple text file generated in my application. The thing is I want to upload this text file on iCloud so that if the user installs app and inputs data he desires and then agin uninstalls this app. Then the next time he installs that app again I want to fetch the text file uploaded the first time he had used the same app.
I am facing a huge problem in integrating iCloud to my app.
I have done much research but didn't got any specific answers.
P.S. = I am not using Core data.
All i want is to upload the text file generated by the app into the iCloud Drive.
Please guide me step by step how can I achieve this. I have my developer account and I have a bit knowledge about the certificates and all. But still if anyone can please guide me how to achieve it.
I JUST WANT TO UPLOAD THE TEXT FILE TO ICLOUD AND RETRIEVE IT AGAIN WHEN THE SAME APP IS INSTALLED AGAIN (EVEN IF THE APP IS GETTING INSTALLED ON OTHER DEVICES).
ViewController.m
#pragma mark - Image Pick
- (IBAction)pickImage:(id)sender {
//select an image
UIImagePickerController *picker = [[UIImagePickerController alloc]init];
picker.delegate = self;
[self presentViewController:picker animated:YES completion:nil];
}
-(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
[self dismissViewControllerAnimated:YES completion:nil];
}
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info
{
[self dismissViewControllerAnimated:YES completion:nil];
UIImage* image = [info objectForKey:UIImagePickerControllerOriginalImage];
self.imageView.image = image;
//SAVE IMAGE IN iCloud
AppDelegate* myAppDelegate = (AppDelegate*)[UIApplication sharedApplication].delegate;
NSURL* cloudeImage = [myAppDelegate applicationCloudFolder:#"thePicture"];
NSData* imageDate = UIImagePNGRepresentation(image);
[imageDate writeToURL:cloudeImage atomically:YES];
}
-(void)populateUI
{
AppDelegate* myAppDelegate = (AppDelegate*)[UIApplication sharedApplication].delegate;
NSURL* cloudeImageURL = [myAppDelegate applicationCloudFolder:#"thePicture"];
NSData* imageDate = [NSData dataWithContentsOfURL:cloudeImageURL];
UIImage* image = [UIImage imageWithData:imageDate];
if (image) {
self.imageView.image = image;
}
else
{
//download image from iCloud
NSLog(#"Downloading Image...");
[[NSFileManager defaultManager]startDownloadingUbiquitousItemAtURL:cloudeImageURL error:nil];
}
}
- (NSMetadataQuery *)query {
if (!_query) {
_query = [[NSMetadataQuery alloc]init];
NSArray *scopes = #[NSMetadataQueryUbiquitousDocumentsScope];
_query.searchScopes = scopes;
NSPredicate *predicate = [NSPredicate predicateWithFormat:#"%K like %#", NSMetadataItemFSNameKey, #"*"];
_query.predicate = predicate;
if (![_query startQuery]) {
NSLog(#"Query didn't start... for whatever reason");
}
}
return _query;
}
AppDelegate.m
-(NSURL*)applicationCloudFolder:(NSString*)fileName
{
//TEAM ID AND CONTAINER ID
NSString* teamID = #"V58ESG9PLE";
NSString* bundelID =[NSBundle mainBundle].bundleIdentifier;
NSString* containerID = [NSString stringWithFormat:#"%#.%#",teamID,bundelID];
// URL to Cloud Folder
NSURL* cloudeRootURL = [[NSFileManager defaultManager] URLForUbiquityContainerIdentifier:containerID];
NSLog(#"cloudeRootURL %#",cloudeRootURL);
NSURL* cloudDocuments = [cloudeRootURL URLByAppendingPathComponent:#"Document"];
//Apend our file name
cloudDocuments = [cloudDocuments URLByAppendingPathComponent:fileName];
return cloudDocuments;
}
Now I am not getting is my data being saved? ,Where is it getting saved? how can I retrieve it?
P.S. I am saving a picture

Send NSData via Airdrop

I've got a (for me) big problem.
I want to send a vcf-file with airdrop from my own app to another iOS device. I've got a NSData object, which i should convert to a vcf file, and this I should send with airdrop to another IOS device.
The NSData object works fine, i can send a vcc file with email, but with airdrop I left my limit.
I tried everything i found here in the forum and on developer.apple.com. But nothing works, I think the reason is, that i have no idea how too start the fix the problem.
Has anybody any idea how i can realize it?
THANKS
I believe this is roughly what you are looking for:
NSString *contactName = nil; // name of person in vcard
NSData *vcfData = nil; // vcard data
NSURL *fileURL = [NSURL fileURLWithPath:[NSTemporaryDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:#"%#.vcf", contactName]]];
NSError *writeError;
if ([vcfData writeToURL:fileURL options:NSDataWritingAtomic error:&writeError]) {
NSArray *activityItems = #[fileURL];
UIActivityViewController *avc = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:nil];
[self presentViewController:avc animated:YES completion:nil];
} else {
// failed, handle errors
}
If you still want to support providing NSData to some of the activities you will have to create some objects that conforms to UIActivityItemSource protocol and have some of them return nil where appropriate (see this SO for more details on that). You might find the AirDrop sample code project from Apple helpful too.

Getting a URL from (to) a "picked" image, iOS

With this code below, I can extract metadata from an image (pre-added to my project), and render the info as text. This is exactly what I want to do. The SYMetadata is created by pointing to an image via URL. initWithAbsolutePathURL. I want to do the same thing with a UIImage or maybe the image that is being loaded to the UIImage. How do I get the URL to the image that the picker selects? Or how do I create an "asset" from this incoming image?
The documentation describes initWithAsset. Have not figured out how to use it yet though, or if this is the right way to go for my purpose. Any help greatly appreciated.
NSURL *imageURL = [[NSBundle mainBundle] URLForResource:#"someImage" withExtension:#"jpg"];
SYMetadata *metadata = [[SYMetadata alloc] initWithAbsolutePathURL:imageURL];
[textView setText:[[metadata allMetadatas] description]];
Note: I tried adding an NSURL like this imageURL = [info valueForKey:#"UIImagePickerControllerReferenceURL"];, in the "pickerDidFinish" method but the metadata is null after I add this URL to the above code.
If you are using the imagePickerController, the delegate method will give you what you need
- (void) imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info
{
if ([[info allKeys] containsObject:UIImagePickerControllerReferenceURL]){
// you will get this key if your image comes from a library
[self setMetaDataFromAssetLibrary:info];
} else if ([[info allKeys] containsObject:UIImagePickerControllerMediaMetadata]){
// if the image comes from the camera you get the metadata in it's own key
self.rawMetaData = [self metaDataFromCamera:info];
}
}
From Asset Library - bear in mind that it takes time to complete and has an asynchronous completion block, so you might want to add a completion flag to ensure you don't access the property before it has been updated.
- (void) setMetaDataFromAssetLibrary:(NSDictionary*)info
{
NSURL *assetURL = [info objectForKey:UIImagePickerControllerReferenceURL];
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
[library assetForURL:assetURL
resultBlock:^(ALAsset *asset) {
self.rawMetaData = asset.defaultRepresentation.metadata;
}
failureBlock:^(NSError *error) {
NSLog (#"error %#",error);
}];
}
From Camera:
- (NSDictionary*)metaDataFromCamera:(NSDictionary*)info
{
NSMutableDictionary *imageMetadata = [info objectForKey:UIImagePickerControllerMediaMetadata];
return imageMetadata;
}
Here is how to get metadata from a UIImage
- (NSDictionary*)metaDataFromImage:(UIImage*)image
{
NSData *jpegData = [NSData dataWithData:UIImageJPEGRepresentation(image, 1.0)];
return [self metaDataFromData:jpegData];
}
But take care - a UIImage can already stripped of much of the metadata from the original.. you will be better off getting the metadata from the NSData that was used to create the UIImage...
- (NSDictionary*)metaDataFromData:(NSData*)data
{
CGImageSourceRef source = CGImageSourceCreateWithData((__bridge CFDataRef)data, NULL);
CFDictionaryRef imageMetaData = CGImageSourceCopyPropertiesAtIndex(source,0,NULL);
return (__bridge NSDictionary *)(imageMetaData);
}
If you've an ALAsset (in my sample _detailItem), you can have metadata in this way:
NSDictionary *myMetadata = [[_detailItem defaultRepresentation] metadata];

Why is MFMailComposeViewController returning MFMailComposeResultFailed?

I'm facing a strange issue in my app and I need your help !
I am using a MFMailComposeViewController to send emails with attachment data. The attachment is either a PDF, a CSV or a XLS file. A ZIP file can also be added to the mail.
Everything works fine in most cases but sometimes (actually quite often), when the attachment is a XLS and a ZIP is added, I receive multiple memory warnings and the composer returns MFMailComposeResultFailed, with an error that doesn't help at all (only saying code error 1, "The operation couldn’t be completed. (MFMailComposeErrorDomain error 1.)").
My question is why does it do that ? I assume the memory warnings are telling me something is not well managed but I can't figure out what...
Here is my code for sending the email
-(void) sendMail {
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
[self prepareMailPicker:picker];
NSString *filePath = [self getFilePath:pType];
NSString *zipFile = [self getZipPath];
NSString *mimeType;
int userPhoto = [User getCSVPhoto];
switch (pType) {
case EPDF:
mimeType = #"application/pdf";
userPhoto = [User getPDFPhoto];
break;
case ECSV:
mimeType = #"text/csv";
break;
case EExcel:
mimeType = #"application/vnd.ms-excel";
break;
default:
break;
}
NSData *attachmentData = [NSData dataWithContentsOfFile:filePath];
[picker addAttachmentData:attachmentData mimeType:mimeType fileName:[filePath lastPathComponent]];
if (userPhoto == 1 && shouldAddZip) {
NSData *zipData = [NSData dataWithContentsOfFile:zipFile];
[picker addAttachmentData:zipData mimeType:#"application/zip" fileName:[zipFile lastPathComponent]];
}
shouldAddZip = NO;
[self presentModalViewController:picker animated:YES];
}
-(void) prepareMailPicker:(MFMailComposeViewController*)picker {
picker.mailComposeDelegate = (id<MFMailComposeViewControllerDelegate>)self;
picker.navigationBar.tintColor = grayDark;
[picker setSubject:[TextManager textForKey:#"EMAIL_SUBJECT"]];
NSString *email = [[User currentUser] getEmail];
if (email && ![email isEqualToString:#""])
[picker setToRecipients:[NSArray arrayWithObject:email]];
NSString *emailBody = [TextManager textForKey:#"EMAIL_TEXT"];
[picker setMessageBody:emailBody isHTML:YES];
}
Any help would be grately apreciated !
EDIT: as asked by #matt, here is a log to prove that nothing is set to nil :
filePath : /var/mobile/Applications/A57F5CD2-E3FE-4417-8810-D746A22CF434/Documents/iNdF_Export_2012-11-19.xls
zipFile : /var/mobile/Applications/A57F5CD2-E3FE-4417-8810-D746A22CF434/Documents/iNdF_recus_2012-11-19.zip
attachmentData : (NSConcreteData *) <0x1d9c3c20> 53 874 bytes
zipData : (NSConcreteData *) <0x1f989100> 6 838 456 bytes
as you say, the problem seems most probably to do with memory management, given the memory warnings you are receiving.
your code is retaining a reference count to the attachmentData from the first file even as it goes out to get the zipData for the second file. internally, the picker is probably copying that data …
so the more you can do to release your references to large data as early as possible, the more likely you are not to get the memory warnings.
and if the problem is that the picker is unable to finish the attachment due to running out of memory, and you are able to get through it by doing early release, then breaking up the code in the following way may help you.
- (void)sendMailPicker:(MFMailComposeViewController*)picker addAttachmentUsingMimeType:(NSString*)mimeType {
NSString *filePath = [self getFilePath:pType];
NSData *attachmentData = [NSData dataWithContentsOfFile:filePath];
[picker addAttachmentData:attachmentData mimeType:mimeType fileName:[filePath lastPathComponent]];
}
- (void)sendMailAddPhotoUsingPicker:(MFMailComposeViewController*)picker {
NSString *zipFile = [self getZipPath];
NSData *zipData = [NSData dataWithContentsOfFile:zipFile];
[picker addAttachmentData:zipData mimeType:#"application/zip" fileName:[zipFile lastPathComponent]];
}
- (void)sendMail {
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
[self prepareMailPicker:picker];
NSString *mimeType;
int userPhoto = [User getCSVPhoto];
switch (pType) {
case EPDF:
mimeType = #"application/pdf";
userPhoto = [User getPDFPhoto];
break;
case ECSV:
mimeType = #"text/csv";
break;
case EExcel:
mimeType = #"application/vnd.ms-excel";
break;
default:
break;
}
[self sendMailPicker:picker addAttachmentUsingMimeType:mimeType];
if (userPhoto == 1 && shouldAddZip) {
[self sendMailAddPhotoUsingPicker:picker];
}
shouldAddZip = NO;
[self presentModalViewController:picker animated:YES];
}
I guess that the problem is related to memory, when you create NSData you create in the heap. If it is to big you'll start to receive memory warnings. One way to avoid memory could be create a memory mapped NSData or an an NSStream but I have no idea on how to integrate a NSStream in mail composer. Which is the average size of your attachment?
You can also try to profile your app with Allocations to see wich is the memory footprint of your app, maybe is already too high.
like the some problems i had faced before.
1. Please check, there is internet availability using "Reachability" class file.
2. Please check your data size is within the limit.
3. Please check you configured your email id with your device.
you can also call [yourobj cansendmail] function to check whether it can send mail or not.

How can I keep track of media created/chosen by UIImagePickerController?

I'm building an iOS app that allows the user to upload videos from UIImagePickerController, either by recording or choosing them from the Camera Roll, as well as also play the chosen video. My question is, how would I go about keeping a reference to the videos that have been chosen this way? I want to do this so that if the video is still present on the device, I can use the local file rather than streaming the uploaded file.
When
imagePickerController:didFinishPickingMediaWithInfo:
returns, the URL in:
[info objectForKey:UIImagePickerControllerMediaURL];
Is in the format of: "file://localhost/private/var/mobile/Applications/ /tmp//trim.z2vLjx.MOV"
I'm lead to believe that the "/tmp/" directory is temporary, and therefore not suitable to save the URL for that location.
I can get all of the videos on the device through ALAssetsLibrary, but because I don't have a way of distinguishing them, this doesn't help me. I've been attempting to use:
[result valueForProperty:ALAssetPropertyDate];
To distinguish the videos, but I need a way of getting the creation date from UIImagePickerController for this to be useful.
I've finally managed to find a solution:
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
NSString* mediaType = [info objectForKey:UIImagePickerControllerMediaType];
if(CFStringCompare((CFStringRef) mediaType, kUTTypeMovie, 0) == kCFCompareEqualTo)
{
//Dismiss the media picker view
[picker dismissModalViewControllerAnimated:YES];
//Get the URL of the chosen content, then get the data from that URL
NSURL *videoURL = [info objectForKey:UIImagePickerControllerMediaURL];
NSData *webData = [NSData dataWithContentsOfURL:videoURL];
//Gets the path for the URL, to allow it to be saved to the camera roll
NSString *moviePath = [[info objectForKey:UIImagePickerControllerMediaURL] path];
if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum (moviePath))
{
ALAssetsLibrary *lib = [[ALAssetsLibrary alloc] init];
//The key UIImagePickerControllerReferenceURL allows you to get an ALAsset, which then allows you to get metadata (such as the date the media was created)
[lib assetForURL:[info objectForKey:UIImagePickerControllerReferenceURL] resultBlock:^(ALAsset *asset) {
NSLog(#"created: %#", [asset valueForProperty:ALAssetPropertyDate]);
} failureBlock:^(NSError *error) {
NSLog(#"error: %#", error);
}];
}
}
As per usual, the solution was found by reading the documentation a little more thoroughly. Hopefully this'll help someone else out at some point.
You can easily keep a record of the videos you have on the device. Either by keeping a data base (which I think would be too much) or just a file with a list of your videos. In that list, you could have the URL of the assets.

Resources