Determine AFP share from a file URL

不想你离开。 提交于 2019-12-06 06:11:08

You need to use some lower-level File Manager routines to get this information, there's no way to do it with regular Cocoa calls. The URL is obtained using FSCopyURLForVolume() but you need to get a volume reference number for the mounted volume in order to use it:

#import <CoreServices/CoreServices.h>

//this is the path to the mounted network volume
NSString* pathToVolume = @"/Volumes/MountedNetworkVolume/";

//get the volume reference number
FSRef pathRef;
FSPathMakeRef((UInt8*)[pathToVolume fileSystemRepresentation],&pathRef,NULL);
FSCatalogInfo catalogInfo;
OSErr osErr = FSGetCatalogInfo(
                               &pathRef,
                               kFSCatInfoVolume,
                               &catalogInfo,
                               NULL,
                               NULL,
                               NULL
                               ) ;
FSVolumeRefNum volumeRefNum = 0;
if(osErr == noErr) 
    volumeRefNum = catalogInfo.volume;

//get the server URL for the volume
CFURLRef serverLocation;
OSStatus result = FSCopyURLForVolume (volumeRefNum,&serverLocation);
if(result == noErr)
    NSLog(@"The server location is: %@",serverLocation);
else
    NSLog(@"An error occurred: %i",result);
CFRelease(serverLocation);

FSMountServerVolumeAsync is definitely the correct way to mount a remote volume.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!