- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
在我的 mac 应用程序中,我需要将文件写入\Library\ColorSync\Profiles。为此,该应用程序需要管理员权限才能读写该文件夹。有可能在应用程序中得到相同的吗?任何帮助将不胜感激。
我可以使用以下代码片段弹出权限对话框
NSSavePanel *tvarNSSavePanelObj = [NSSavePanel savePanel];
[tvarNSSavePanelObj setDirectoryURL:[NSURL URLWithString:@"/Library/ColorSync/Profiles"]];
__block NSString *filePathexn = nil;
[tvarNSSavePanelObj beginSheetModalForWindow:[NSApplication sharedApplication].mainWindow completionHandler:^(NSInteger tvarInt) {
if(tvarInt == NSModalResponseOK){
NSURL* tvarUrl = [tvarNSSavePanelObj URL];
NSLog(@"doSaveAs filename = %@",[tvarUrl path]);
NSString *filePath = [tvarUrl path];
filePathexn = [filePath stringByAppendingPathExtension:@"rtf"];
OSStatus status;
if(![[NSFileManager defaultManager]isWritableFileAtPath:filePath]){
NSLog(@"Not Writable at path");
AuthorizationRef authRef;
AuthorizationItem right = {kAuthorizationRightExecute, 0, NULL, 0};
AuthorizationRights rights = {1, &right};
status = AuthorizationCreate(NULL, kAuthorizationEmptyEnvironment, kAuthorizationFlagPreAuthorize, &authRef);
AuthorizationFlags authFlags = kAuthorizationFlagDefaults | kAuthorizationFlagExtendRights | kAuthorizationFlagInteractionAllowed | kAuthorizationFlagPreAuthorize;
status = AuthorizationCopyRights(authRef, &rights, kAuthorizationEmptyEnvironment, authFlags, NULL);
}
BOOL status1 = [[NSFileManager defaultManager]createFileAtPath:filePathexn contents:nil attributes:nil];
} else if(tvarInt == NSModalResponseCancel) {
return;
} else {
NSLog(@"doSave As tvarInt not equal 1 or zero = %3ld",(long)tvarInt);
return;
}
}];
我需要知道如何完成文件写入。静止文件未写入路径。是否需要指定任何工具名称? SMJobless() 有可能吗?请提出解决方案!!
最佳答案
我在这里发布的另一个解决方案。我浏览了应用程序分发指南。有人提到,对于在应用程序商店之外分发的应用程序,不建议使用授权 APIS。这个解决方案对我有用的任何方式,它是一个小黑客,我不知道。我尝试从应用程序运行 apple 脚本,它为文件夹(chmod 777 路径)提供完全权限,并在完成我的任务后设置回以前的权限集。
- (void)runapplescript{
NSDictionary* errorDict;
NSAppleEventDescriptor* returnDescriptor = NULL;
NSAppleScript* scriptObject = [[NSAppleScript alloc] initWithSource:
@"do shell script \"chmod 777 /Library/ColorSync/Profiles\" with administrator privileges"];
returnDescriptor = [scriptObject executeAndReturnError: &errorDict];
}
关于objective-c - 获得在 mac 应用程序中将文件写入\Library\ColorSync\Profiles\的权限,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34717355/
我正在 try catch 显示器的内容并将显示器的色彩空间转换为 sRGB。我正在尝试使用 vImage 和低级 ColorSync 转换 API 来执行此操作,但输出的像素 block 奇怪地加倍
我正在升级一个一直使用 ColorSync Manager API 的 OS X 应用程序获取连接显示器的颜色配置文件。 OS X 10.6 左右就已经是不祥之兆,当时 API 中的所有内容都被标记为
我正在尝试在我的应用程序中创建一个 PDF,并且一切正常,除了当我在模拟器或设备上运行我的项目时,我在一行没有崩溃的代码上得到一个异常断点应用程序,但会生成 *** ImageIO - 找不到 Col
在我的 mac 应用程序中,我需要将文件写入\Library\ColorSync\Profiles。为此,该应用程序需要管理员权限才能读写该文件夹。有可能在应用程序中得到相同的吗?任何帮助将不胜感激。
当使用 Xcode 9 (9A235) 在 Sierra (10.12.6) 上构建 macOS 应用程序时,由于 ColorSync 框架,应用程序将无法正常启动 - dyld 无法找到它: Ter
我是一名优秀的程序员,十分优秀!