This is very common error that happens when you try to create a file on the file system and a file with the same name already exists. You can avoid that by checking whether a file with the name already exists or not. If it does exists then remove it and try to create again.
Error 516 is NSFileWriteFileExistsError - You can't move a file to a place where a file already exists.
The below code does not check for this and can lead to above error:
NSString *docDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *destSpecFile = [NSString stringWithFormat:@"%@/%@", docDir,gallerySpecFile];
NSString *srcPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:gallerySpecFile];
[[NSFileManager defaultManager] copyItemAtPath:srcPath
Before attempting the copyItemAtPath, check the destination file and if there, remove it.