【问题标题】:Mount Network Drives when Sandbox Mode is ON沙盒模式开启时挂载网络驱动器
【发布时间】:2017-03-26 20:13:46
【问题描述】:

我已经使用NetFSMountURLSync 和不同的协议(AFP、SMB、NFS 和 NFS(Final cut 协议))实现了网络驱动器安装。下面提到的是我实现它的代码。

示例网址:smb://10.64.104.215/

安装路径示例:file:///Volumes/

NSURL *url = [[NSURL alloc] initWithString:mountURLString];

NSURL *mountpath = [NSURL fileURLWithPath:@"/Volumes/" isDirectory:YES];

CFMutableDictionaryRef mountOpts = CFDictionaryCreateMutable(NULL, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);

CFDictionarySetValue(mountOpts, kNetFSMountAtMountDirKey, CFSTR("MountAtMountDir"));

CFArrayRef mountpoints = NULL;

NSInteger error = NetFSMountURLSync(
                                    (__bridge CFURLRef) url,
                                    (__bridge CFURLRef) mountpath,
                                    NULL,
                                    NULL ,
                                    0,
                                    mountOpts,
                                    &mountpoints);

沙盒模式关闭时可以正常工作,但沙盒模式打开时上面的代码不起作用。根据 Error.h 文件,它将错误返回为 1,即 “Operation not permitted”。我知道沙盒模式有一些限制,但是对于我的应用程序来说,挂载网络驱动器很重要,因为它是我的应用程序的核心功能之一。当沙盒模式打开时,如何实现网络驱动器安装功能。任何帮助表示赞赏。提前致谢。

【问题讨论】:

    标签: macos appstore-sandbox


    【解决方案1】:

    我通过将挂载路径更改为应用容器内的某个位置来实现这一点。我从苹果论坛上的一位开发人员技术支持人员那里收到了这个解决方案。

    以下是相同的编辑和工作代码:

    NSURL *url = [[NSURL alloc] initWithString:mountURLString];
    
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0]; // Get documents folder
    
    NSURL *mountpath = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/", documentsDirectory] isDirectory:YES];
    
    CFMutableDictionaryRef mountOpts = CFDictionaryCreateMutable(NULL, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
    
    CFDictionarySetValue(mountOpts, kNetFSMountAtMountDirKey, CFSTR("MountAtMountDir"));
    
    CFArrayRef mountpoints = NULL;
    
    NSInteger error = NetFSMountURLSync(
                                        (__bridge CFURLRef) url,
                                        (__bridge CFURLRef) mountpath,
                                        NULL,
                                        NULL ,
                                        0,
                                        mountOpts,
                                        &mountpoints);
    

    【讨论】:

    • 我遇到了相关问题。当我将 kNetFSMountAtMountDirKey 设置为 false 并指定挂载点时,实际发生挂载的位置位于我指定的挂载点下方。如果我将其设置为 true,则调用失败,返回码为 1。知道如何强制它安装在我想要的位置吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-15
    相关资源
    最近更新 更多