1

我有以下代码,并且不断收到 EXC_BAD_ACCESS 错误。我发布了此代码的更复杂副本,但我将问题归结为以下代码:

#import <Foundation/Foundation.h>
#include <NetFS/NetFS.h>

int main(int argc, const char * argv[]){
    @autoreleasepool {

        NSURL * share = [NSURL URLWithString: @"smb://192.168.0.100/lib"];
        NSURL * path = [NSURL URLWithString: @"/Users/bogdan/Network/Library/"];
        CFURLRef share2 = (__bridge CFURLRef) share;
        CFURLRef path2 = (__bridge CFURLRef) path;

        NetFSMountURLSync(share2, path2, NULL, NULL, NULL, NULL, NULL);
    }
    return 0;
}

问题出在“NetFSMountURLSync”行,但我不知道问题出在哪里。我认为我使用它是正确的,我删除了所有可以选择的选项。运行此程序后,共享已安装,但此后我收到错误消息。

4

1 回答 1

1

知道了!显然,即使我不关心返回的挂载点,我仍然必须将变量传递给函数,以便它可以将其存储在那里。此代码有效:

int main(int argc, const char * argv[]){

@autoreleasepool {

    NSURL * share = [NSURL URLWithString: @"smb://192.168.0.100/lib"];
    NSURL * path = [NSURL URLWithString: @"/Users/bogdan/Network/Library/"];
    CFURLRef share2 = (__bridge CFURLRef) share;
    CFURLRef path2 = (__bridge CFURLRef) path;
    CFArrayRef mountpoints = NULL;

    NetFSMountURLSync(share2, path2, NULL, NULL, NULL, NULL, &mountpoints);
}
return 0;
}
于 2013-09-26T03:20:23.620 回答