ios – NSFileManager创建目录错误518 NSFileWriteUnsupportedSchemeError

前端之家收集整理的这篇文章主要介绍了ios – 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}

也许网址是错的?

解决方法

代替
[NSURL URLWithString:BIDirectory]

请用

[NSURL fileURLWithPath:BIDirectory]

在本地文件上使用URLWithString:BIDirectory的错误

原文链接:https://www.f2er.com/iOS/336662.html

猜你在找的iOS相关文章