问题描述
我注意到 copyItemAtURL:toURL:error:和 moveItemAtURL:toURL:error:方法在iOS 14 beta 7上具有不同的行为。
方法-(BOOL)copyItemAtURL:(NSURL *)srcURL到URL:(NSURL *)dstURL错误:(NSError * _Nullable *)错误;
来自Apple文档:“如果dstURL中已经存在同名文件,则此方法将停止复制尝试并返回适当的错误。”
在装有 iOS 13 的设备上,此方法可以正常工作。 It returns an error because the file already exists at dstURL 但是在 iOS 14 上却相反。 It copies the file without errors。
代码示例:
NSData *fileContents = [@"Put this in a file" dataUsingEncoding:NSUTF8StringEncoding];
Nsstring *directory = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES)[0];
Nsstring *filePath = [directory stringByAppendingPathComponent:@"test.txt"];
NSFileManager *manager = [NSFileManager defaultManager];
[manager createFileAtPath:filePath
contents:fileContents
attributes:nil];
NSError *error = nil;
NSURL *url = [NSURL fileURLWithPath:filePath];
BOOL result = [manager copyItemAtURL:url toURL:url error:&error];
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)