美文网首页
Mac应用文件夹权限

Mac应用文件夹权限

作者: ___________枫林晚 | 来源:发表于2018-01-05 17:19 被阅读0次

    Mac 应用程序的开发比较少,所以搜索的资料比较少,这里记录一下我自己的经验,以作备份。

    如图可以在sandbox中勾选自己需要的权限和文件夹访问权限,里面有一个User Selected File,这个比较实用


    1.png

    为此我们可在需要选择文件夹的地方添加如下代码

        __weak typeof(self)weakSelf = self;
        NSOpenPanel* panel = [NSOpenPanel openPanel];
        panel.canCreateDirectories = YES;
        panel.canChooseDirectories = YES;
        panel.canChooseFiles = YES;
        [panel setAllowsMultipleSelection:NO];
        [panel beginSheetModalForWindow:self.view.window completionHandler:^(NSInteger result) 
        {
            if (result == NSModalResponseOK)
             {
                //NSURL *pathUrl = [panel URL];
                NSString *pathString = [panel.URLs.firstObject path];
                weakSelf.urlTextField.stringValue = pathString;
              }
        }];
    //    [panel beginWithCompletionHandler:^(NSInteger result){}];
    

    需要提的是此方法需要在window创建成功以后调用,否则会报 unknow window class;

    相关文章

      网友评论

          本文标题:Mac应用文件夹权限

          本文链接:https://www.haomeiwen.com/subject/nbysnxtx.html