FSMountServerVolumeSync 参数目标 c [英] FSMountServerVolumeSync parameter objective c

查看:55
本文介绍了FSMountServerVolumeSync 参数目标 c的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用 Applescript 之后,我刚刚开始使用 Objective C,而且我似乎无法让 FSMountServerVolumeSync 工作.这看起来像是一个完全初学者的问题,但是如何将参数从变量传递到此操作?

我来解释一下:
我想在此操作中获取一个名为 *username 的变量并将其设置为用户名.我也想对 *url 和 url 这样做.从绝对初学者的角度来看,有什么方法可以向我展示如何设置它的示例?我目前正在阅读教程等,但即使我不完全理解我在做什么,我也想完成这部分代码.;)
提前致谢!

这是我目前得到的:

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);


} 

推荐答案

这些根本不是愚蠢的问题.

These aren't dumb questions at all.

请记住,CFStringRef 和 CFURLRef 是免费桥接,这意味着 Objective C 的等效项是 NSString 和 NSURL.您需要做的就是投射.

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?

这是一些关于免费桥接类型的 Apple 文档.

这篇关于FSMountServerVolumeSync 参数目标 c的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆