Tôi đang cố gắng sao chép tệp mp3 từ thư mục Tài nguyên của mình vào thư mục bên trong thư mục "Tài liệu" của ứng dụng. Trên giả lập này hoạt động tốt. Nhưng khi tôi chạy nó trên một thiết bị, sao chép các tập tin mang lại cho tôi lỗi nàyiPhone - sao chép tệp từ tài nguyên sang Tài liệu đưa ra lỗi
Operation could not be completed. (Cocoa error 513.)
Đường dẫn nguồn và đích là tốt nhưng tôi vẫn không thể sao chép tệp. Bất kỳ ý tưởng? Tôi có thể tìm hiểu mã lỗi 513 ở đâu?
Cảm ơn.
Dưới đây là mã nguồn có liên quan
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *folderPath = [documentsDirectory stringByAppendingPathComponent:@"Files"];
NSString *insPath = [NSString stringWithFormat:@"%@.mp3", fileName];
NSString *srcPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:insPath];
NSString *destPath = [folderPath stringByAppendingPathComponent:insPath];
NSLog(@"Src: %@, Dest: %@", srcPath, destPath);
NSError *err;
[fileManager moveItemAtPath:srcPath toPath:destPath error:&err];
NSLog(@"Err desc-%@", [err localizedDescription]);
NSLog(@"Err reason-%@", [err localizedFailureReason]);
Trước khi thực hiện một cuộc gọi đến moveItemAtPath, tôi cũng đang tạo ra những thư mục "Files" và nó trả về một YES.
Dưới đây là các bản ghi kết quả
Src: /var/mobile/Applications/512D7565-7EF7-4C13-A015-19EEC3F3B465/MyApp.app/MyFile.mp3, Dest: /var/mobile/Applications/512D7565-7EF7-4C13-A015-19EEC3F3B465/Documents/Files/MyFile.mp3
Err desc-Operation could not be completed. (Cocoa error 513.)
Err reason-(null)
Một câu hỏi
Có giới hạn kích thước tập tin khi sao chép dữ liệu từ nguồn vào thư mục Documents? Tệp tôi đang cố gắng sao chép là khoảng 5MB. Đó có thể là một lý do?
dup có thể có của: http://stackoverflow.com/questions/912828/how-do-i-fix-cocoa-error-513 – notnoop
Đã thấy câu hỏi rồi. Giải pháp ở đó không giúp được sự cố của tôi – lostInTransit
có thể sẽ giúp ích nếu bạn có thể đưa mã vào để sao chép tệp. – notnoop