本文介绍了NSFileManager创建目录错误518 NSFileWriteUnsupportedSchemeError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试创建目录
NSError*error=nil;
NSString* BIDirectory=[[NSSearchPathForDirectoriesInDomains(NSCachesDirectory,NSUserDomainMask,YES) objectAtIndex:0] stringByAppendingPathComponent:@"BI"];
BOOL isDir,flag=YES;
//if the directory doesn't exist create it.
if(!([[NSFileManager defaultManager] fileExistsAtPath:BIDirectory isDirectory:&isDir]&& isDir))
flag=[[NSFileManager defaultManager] createDirectoryAtURL:[NSURL URLWithString:BIDirectory] withIntermediateDirectories:YES attributes:nil error:&error];
我遇到以下错误
enter code hereError Domain=NSCocoaErrorDomain Code=518 "The operation couldn’t be completed. (Cocoa error 518.)" UserInfo=0x197190 {NSURL=/var/mobile/Applications/55793654-6CDB-4B07-8FBF-553DC37D583D/Library/Caches/BI}
URL可能是错误的吗?
maybe the url is wrong?
推荐答案
代替
[NSURL URLWithString:BIDirectory]
请使用
[NSURL fileURLWithPath:BIDirectory]
在本地文件上使用URLWithString:BIDirectory是错误的
its wrong to use URLWithString:BIDirectory on local files
这篇关于NSFileManager创建目录错误518 NSFileWriteUnsupportedSchemeError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!