Unable to create directory on some devices

Hi,


I'd like to download a zip file and move the downloaded file using this code snippet:


NSFileManager *fileManager = [NSFileManager defaultManager];
BOOL isDir;
NSString *path = ...;
NSString *targetPath = ...;
             
NSString *targetDirectory = [targetPath stringByDeletingLastPathComponent];
if (![fileManager fileExistsAtPath:targetDirectory isDirectory:&isDir] && !isDir)
{
     NSError *dirError;
     if (! [fileManager createDirectoryAtPath:targetDirectory withIntermediateDirectories:YES attributes:nil error:&dirError])
     {
          NSLog(@"%@", dirError.localizedDescription);
     }
}


//...



if ([fileManager moveItemAtPath:path toPath:targetPath error:&error])
{
     success = YES;
}


It has worked fine on our test devices and it has also worked fine on iOS 8.x. Now, some beta tester have reported that moving the zip file fails on devices with iOS 9.x because the target directory does not exist. Not in general, only on a few devices running iOS 9.x. I have updated our test devices to iOS 9.1 and it still works. The zip file is the same for all test users.


So, what next? It works on our test devices, but not on some others. Does anybody know if there are known bugs in iOS 9.x while creating directories or moving files? Does anybody have any idea what to do here?


Thanks a lot for your response.


Michael

Answered by Documentation Engineer in 90475022

It would be helpful to see some specific paths that are failing. And knowing where the path and targetPath strings are actually coming from might also be useful.

Accepted Answer

It would be helpful to see some specific paths that are failing. And knowing where the path and targetPath strings are actually coming from might also be useful.

Unable to create directory on some devices
 
 
Q