FSMountServerVolumeSync parameter objective c

别来无恙 提交于 2019-12-07 22:19:35

问题


I'm just starting Objective C after being pampered with Applescript, and I can't seem to get FSMountServerVolumeSync to work. This is going to seem like a completely beginner question, but how do you pass a parameter from a variable to this action?

Let me explain:
I want to take a variable called *username and set it to the username in this action. I would also like to do this to *url and url. Is there any way someone could show me a sample of how to set this up, from an absolute beginner standpoint? I am currently reading through tutorials and etc., but I would like to get this section of code done even if I don't exactly understand what I'm doing. ;)
Thanks in advance!

[edit] Here's what I've got so far:

- (IBAction)signin:(id)sender{

NSString * user = @"myusername";
NSString * password = @"mypassword";
NSURL * url = [NSURL URLWithString: @"smb://123.456.789.0"];
NSURL * mountDir = [NSURL URLWithString: @"/Students"];

OSStatus FSMountServerVolumeSync (
                                  CFURLRef url, 
                                  CFURLRef mountDir, 
                                  CFStringRef user, 
                                  CFStringRef password, 
                                  FSVolumeRefNum *null, 
                                  OptionBits flags);


} 

回答1:


These aren't dumb questions at all.

Remember that CFStringRef and CFURLRef are toll free bridged, which means that the Objective C equivalents are NSString and NSURL. All you need to do is cast.

- (IBAction)signin:(id)sender{

    NSString * user = @"myusername";
    NSString * password = @"mypassword";
    NSURL * url = [NSURL URLWithString: @"smb://123.456.789.0"];
    NSURL * mountDir = [NSURL URLWithString: @"/Students"];
    OptionBits flags = 0;
    OSStatus err = FSMountServerVolumeSync (
                                      (CFURLRef) url, 
                                      (CFURLRef) mountDir, 
                                      (CFStringRef) user, 
                                      (CFStringRef) password, 
                                      NULL, 
                                      flags);

    if(err != noErr)
        NSLog( @"some kind of error in FSMountServerVolumeSync - %ld", err );
} 

See what I mean so far?

Here is some Apple documentation on toll free bridged types.



来源:https://stackoverflow.com/questions/8046063/fsmountservervolumesync-parameter-objective-c

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