NSString *tempDirectoryTemplate =
[NSTemporaryDirectory() stringByAppendingPathComponent:@”myapptempdirectory.XXXXXX”];
const char *tempDirectoryTemplateCString =
[tempDirectoryTemplate fileSystemRepresentation];
char *tempDirectoryNameCString =
(char *)malloc(strlen(tempDirectoryTemplateCString) + 1);
strcpy(tempDirectoryNameCString, tempDirectoryTemplateCString);

char *result = mkdtemp(tempDirectoryNameCString);
if (!result)
{
// handle directory creation failure
}

NSString *tempDirectoryPath =
[NSString
stringWithFileSystemRepresentation:tempFileNameCString
length:strlen(result)];
free(tempDirectoryNameCString);

Advertisements