I have the following code that compiles on Pre OSX 10.13 machines
FSRef ref;
OSType folderType = kApplicationSupportFolderType;
char path_c[PATH_MAX];
FSFindFolder(kUserDomain, folderType, kCreateFolder, &ref);
FSRefMakePath( &ref, (UInt8*)&path_c, PATH_MAX);
I need this to work on the latest versions. How can I change this? It currently says such an API does not exist
The modern equivalent requires Objective-C(++) or Swift. In Objective-C, it would be:
NSFileManager *fm = [NSFileManager new];
NSURL *url = [fm URLForDirectory:NSApplicationSupportDirectory
inDomain:NSUserDomainMask
appropriateForURL:nil
create:YES
error:NULL];
char path_c[PATH_MAX];
[url getFileSystemRepresentation:path_c maxLength:sizeof(path_c)];
I don't know exactly how you will use path_c
. If you only need a pointer to a C string for the path and it won't be used after the url
object has been released, you could use url.fileSystemRepresentation
, instead. Even better, switch to using APIs that take URLs rather than path strings, where possible.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.