Skip to content

Instantly share code, notes, and snippets.

@eahrold
Created February 12, 2015 15:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eahrold/61658882c0901097fb88 to your computer and use it in GitHub Desktop.
Save eahrold/61658882c0901097fb88 to your computer and use it in GitHub Desktop.
Most basic cocoa based network mount. Set to NOT prompt for user interaction.
#import <NetFS/NetFS.h>
///....////
- (void)mount:(NSURL *)networkShare user:(NSString *)user password:(NSString *)password
{
NSURL *mountPath = [NSURL URLWithString:@"/Volumes/"];
dispatch_queue_t myQueue = dispatch_get_main_queue();
AsyncRequestID requestID = NULL;
/*
* The following dictionary keys for open_options are supported:
*
* kNetFSUseGuestKey: Login as a guest user.
*
* kNetFSAllowLoopbackKey Allow a loopback mount.
*
* kNAUIOptionKey = UIOption Suppress authentication dialog UI.
* kNAUIOptionNoUI
* kNAUIOptionAllowUI
* kNAUIOptionForceUI
*/
/*
* The following dictionary keys for mount_options are supported:
*
* kNetFSMountFlagsKey = MNT_DONTBROWSE No browsable data here (see <sys/mount.h>).
*
* kNetFSMountFlagsKey = MNT_RDONLY A read-only mount (see <sys/mount.h>).
*
* kNetFSAllowSubMountsKey = true Allow a mount from a dir beneath the share point.
*
* kNetFSSoftMountKey = true Mount with "soft" failure semantics.
*
* kNetFSMountAtMountDirKey = true Mount on the specified mountpath instead of below it.
*
* Note that if kNetFSSoftMountKey isn't set, then it's set to TRUE.
*
*/
NSMutableDictionary *openOptions = [@{
(__bridge NSString *)kNAUIOptionKey : (__bridge NSString *)kNAUIOptionNoUI,} mutableCopy ];
NSMutableDictionary *mountOptions = [@{
(__bridge NSString *)kNetFSAllowSubMountsKey : @YES,
} mutableCopy
];
int rc = NetFSMountURLAsync((__bridge CFURLRef)networkShare,
(__bridge CFURLRef)mountPath,
(__bridge CFStringRef)(user),
(__bridge CFStringRef)(password),
(__bridge CFMutableDictionaryRef)(openOptions),
(__bridge CFMutableDictionaryRef)(mountOptions),
&requestID,
myQueue,
^(int status, AsyncRequestID requestID, CFArrayRef mountpoints) {
NSLog(@"Mounting status code: %d", status);
});
NSLog(@"Request status code: %d", rc);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment