从我的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()可以实现吗?请建议解决方案!!