jeudi 25 décembre 2014

copyItemAtPath return NO but the error is nil during unit testing

I have a following code, which copies folder from the app bundle to the Documents folder.



- (void)moveTessdataToDocumentsDirectoryIfNecessary
{
// Useful paths
NSFileManager *fileManager = [NSFileManager defaultManager];

// Create specified folder in the Documents directory first
if ([fileManager fileExistsAtPath:self.dataPath] == NO) {
[fileManager createDirectoryAtPath:self.dataPath withIntermediateDirectories:YES attributes:nil error:nil];
}

NSString *tessdataFolderName = @"tessdata";
NSString *tessdataPath = [[NSBundle bundleForClass:self.class].resourcePath stringByAppendingPathComponent:tessdataFolderName];
NSString *destinationPath = [self.dataPath stringByAppendingPathComponent:tessdataFolderName];
if([fileManager fileExistsAtPath:destinationPath] == NO && [fileManager fileExistsAtPath:tessdataPath]) {
NSError *error = nil;
NSLog(@"found %@", tessdataPath);
NSLog(@"coping in %@", destinationPath);
BOOL res = [fileManager copyItemAtPath:tessdataPath toPath:destinationPath error:&error];
if (!res) {
NSLog(@"The result of copyItemAtPath == NO");
}
if(error != nil) {
NSLog(@"ERROR! %@", error.description);
}
}
}


It works fine in a sumilator and in a device.


The issue happens when I start unit tests for this function. The output while unit testing is:



found /Users/kmakankov/Library/Developer/CoreSimulator/Devices/D28F7234-8C28-4325-BE7D-4DF113DF427E/data/Containers/Bundle/Application/EBD5C654-897B-4066-885B-986553D3459F/http://ift.tt/13GLgvT
coping in /Users/kmakankov/Library/Developer/CoreSimulator/Devices/D28F7234-8C28-4325-BE7D-4DF113DF427E/data/Containers/Data/Application/50D673A6-3F3E-42A1-98A1-DEAF9A4B2FBE/Documents/tes/tessdata
The result of copyItemAtPath == NO


So as you can see the copyItemAtPath return NO, but there is no error message, so I cannot understand what is the reason of the issue. Furthemore, If I change copyItemAtPath with moveItemAtPath the function correctly moves the folder from the source to the destination during unit testing, so both source and destination paths are correct.


Does anybody knows what's wrong with copyItemAtPath?


Some extra info. I use iOS SDK 8.1.


Aucun commentaire:

Enregistrer un commentaire