简体   繁体   English

如何使用SMJobBless功能在Mac上的/ Library / Fonts文件夹中写入

[英]How Write on /Library/Fonts folder on Mac with SMJobBless function

I try to use SMJobBless function to authenticate for my application can do write on /Library/Fonts but not working, 我尝试使用SMJobBless函数进行身份验证,因为我的应用程序可以在/ Library / Fonts上写但不能正常工作,

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];
}

My application printed "Job is available" but when i check authorities write on /Library/Fonts, result is false 我的应用程序打印“作业可用”,但是当我检查授权机构在/ Library / Fonts上书写时,结果为false

Please tell me reason and resolve it. 请告诉我原因并解决。

The idea of SMJobBless is that privileged functionality is separated from the main application and run in a helper application. SMJobBless的想法是特权功能与主应用程序分离,并在帮助程序中运行。

Therefore, in the case of your example code, you're just using the helper app to test authentication, when in actuality, you should be doing the privileged task of checking if the path is writable from the helper app, as the helper app is provided with the privileged access. 因此,就示例代码而言,您只是在使用助手应用程序来测试身份验证,实际上,您应该执行特权任务,检查是否可以从助手应用程序写入路径,因为助手应用程序是提供特权访问。

Then if you're going to write to the fonts folder, the privileged helper app should do that, not your main application. 然后,如果要写入fonts文件夹,则特权助手应用程序应该执行此操作,而不是主应用程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM