Ich portiere meine Anwendung von XCode7 und iOS 9.x zu XCode8 und iOS10. Ich habe Probleme mit der Handhabung der Dateien.Datei von Dokumenten nach tmp verschieben XCode 8 iOS 10
Ich muss eine Datei von meinem Backend herunterladen und danach von /Documents
zu /tmp
verschieben. Hier ist mein Code:
AFURLSessionManager *manager = ...
NSURLSessionDownloadTask *downloadTask = [manager downloadTaskWithRequest:request progress:nil destination:^NSURL *(NSURL *targetPath, NSURLResponse *response) {
NSURL *documentsDirectoryPath = [NSURL fileURLWithPath:[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject]];
return [documentsDirectoryPath URLByAppendingPathComponent:[response suggestedFilename]];
} completionHandler:^(NSURLResponse *response, NSURL *filePath, NSError *error) {
if(error) {
...
} else {
NSFileManager *fileManager = [NSFileManager defaultManager];
NSError *error;
NSString *tmpDirectory = NSTemporaryDirectory();
NSString *tmpPDFPath = [tmpDirectory stringByAppendingPathComponent:[[response suggestedFilename] stringByReplacingOccurrencesOfString:@" " withString:@""]];
if ([fileManager fileExistsAtPath:tmpPDFPath] == YES) {
[fileManager removeItemAtPath:tmpPDFPath error:&error];
}
NSLog(@"readable %d", [fileManager isReadableFileAtPath:filePath]);
// Print TRUE
NSLog(@"tmpWritable %d", [fileManager isWritableFileAtPath:[NSURL URLWithString:tmpDirectory]]);
// Print TRUE
BOOL move = [fileManager moveItemAtPath:filePath toPath:tmpPDFPath error:&error];
...
}
}];
Alles funktioniert gut, wenn ich meine Anwendung in einem iOS 9.3 Simulator laufen, aber die App stürzt ab, wenn in einem iOS10 einem Lauf. Die erste Änderung, die ich vornehmen musste, ist die moveItemAtPath
Methode filePath.absoluteString
anstelle von filePath
. Trotz dieser Bearbeitung, der Umzug Methode versagt immer mit diesem Fehler:
Error Domain=NSCocoaErrorDomain Code=4 "“XXXX.pdf” couldn’t be moved to “tmp” because either the former doesn't exist, or the folder containing the latter doesn't exist." UserInfo={NSSourceFilePathErrorKey=/file:/Users/XXX/Library/Developer/CoreSimulator/Devices/24CAB2B2-F495-4CFF-90A7-5C51AF38C194/data/Containers/Data/Application/3D8EEEF9-F639-4D6C-BD5E-17A571F7B836/Documents/XXXX.pdf, NSUserStringVariant=( Move ), NSFilePath=/file:/Users/XXXX/Library/Developer/CoreSimulator/Devices/24CAB2B2-F495-4CFF-90A7-5C51AF38C194/data/Containers/Data/Application/3D8EEEF9-F639-4D6C-BD5E-17A571F7B836/Documents/“XXXX.pdf, NSDestinationFilePath=/Users/“XXXX/Library/Developer/CoreSimulator/Devices/24CAB2B2-F495-4CFF-90A7-5C51AF38C194/data/Containers/Data/Application/3D8EEEF9-F639-4D6C-BD5E-17A571F7B836/tmp/“XXXX.pdf, NSUnderlyingError=0x7b0a3500 {Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory"}}
Hat jemand bereits mit dieser Art von Fehler behandelt?