您需要使用一些较低级别的文件管理器例程来获取此信息,使用常规 Cocoa 调用无法做到这一点。URL 是使用获取的,FSCopyURLForVolume()
但您需要获取已安装卷的卷参考号才能使用它:
#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
绝对是安装远程卷的正确方法。