Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSFileManager creating directory error 518 NSFileWriteUnsupportedSchemeError

I was trying to create a directory

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];

i got the following 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}

maybe the url is wrong?

like image 335
LolaRun Avatar asked May 24 '12 19:05

LolaRun


1 Answers

Instead of

    [NSURL URLWithString:BIDirectory]

please use

    [NSURL fileURLWithPath:BIDirectory]

its wrong to use URLWithString:BIDirectory on local files

like image 130
Omar Abdelhafith Avatar answered Oct 15 '22 05:10

Omar Abdelhafith