I have implemented Network drive mounting using NetFSMountURLSync with different protocols (AFP, SMB, NFS and NFS (Final cut protocol)). Below mentioned is my code to achieve it.
Example url : smb:/
Example mount path : file:/
NSURL *url = [[NSURL alloc] initWithString:mountURLString];
NSURL *mountpath = [NSURL fileURLWithPath:@"/Volumes/" isDirectory:YES];
CFMutableDictionaryRef mountOpts = CFDictionaryCreateMutable(NULL, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
CFDictionarySetValue(mountOpts, kNetFSMountAtMountDirKey, CFSTR("MountAtMountDir"));
CFArrayRef mountpoints = NULL;
NSInteger error = NetFSMountURLSync(
(__bridge CFURLRef) url,
(__bridge CFURLRef) mountpath,
NULL,
NULL ,
0,
mountOpts,
&mountpoints);
It works fine when Sandbox Mode is OFF but the above code doesn’t work when Sandbox mode is ON. It returns me error as 1 which is “Operation not permitted” according to the Error.h file. I know there are restrictions in Sandbox mode, but its important for my application to mount network drives because its one of the core features of my application. Any help is appreciated. Thanks in advance.