Macos 如何使用SMJobBless功能在Mac上的/Library/Fonts文件夹中写入
我尝试使用SMJobBless函数来验证我的应用程序是否可以在/Library/font上写入,但不起作用Macos 如何使用SMJobBless功能在Mac上的/Library/Fonts文件夹中写入,macos,authentication,objective-c,Macos,Authentication,Objective C,我尝试使用SMJobBless函数来验证我的应用程序是否可以在/Library/font上写入,但不起作用 if (![self blessHelperWithLabel:@"com.apple.bsd.SMJobBlessHelper" error:&error]) { NSLog(@"Something went wrong! %@ / %d", [error domain], (int) [error code]); } else { //Access to this point.
if (![self blessHelperWithLabel:@"com.apple.bsd.SMJobBlessHelper" error:&error]) {
NSLog(@"Something went wrong! %@ / %d", [error domain], (int) [error code]);
} else {
//Access to this point.
/* At this point, the job is available. However, this is a very
* simple sample, and there is no IPC infrastructure set up to
* make it launch-on-demand. You would normally achieve this by
* using XPC (via a MachServices dictionary in your launchd.plist).
*/
NSLog(@"Job is available!");
bool result = false;
result = [[NSFileManager defaultManager] isWritableFileAtPath:@"/Library/Fonts"];
[self->_textField setHidden:false];
}
我的应用程序打印了“工作可用”,但当我检查权限是否写在/Library/font上时,结果为false
请告诉我原因并解决它。SMJobBless的思想是特权功能与主应用程序分离,并在助手应用程序中运行 因此,在示例代码中,您只是使用helper应用程序测试身份验证,而实际上,您应该执行特权任务,检查路径是否可从helper应用程序写入,因为helper应用程序具有特权访问权限
然后,如果您要写入字体文件夹,特权助手应用程序应该这样做,而不是您的主应用程序。这是您的主应用程序中的代码,还是助手中的代码?您好,这是我的主应用程序。您好,但在SMJobBless项目中,我不知道在SMJobblesHelper文件夹中检查可写内容的位置。您需要使用XPC在主应用程序及其帮助程序之间进行通信。这里有一个关于这个的讨论: