Created
February 12, 2015 15:16
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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