事实上,我阅读了以下文件:
不是很明白,有大神知道怎么弄吗?
还有,这是什么意思:
注意:在调用 SMLoginItemSetEnabled 函数之前,首先通过使用帮助应用程序包的 URL 调用 LSRegisterURL 函数向 Launch Services 注册。
有没有关于如何使用LSRegisterURL和SMLoginItemSetEnabled的示例?
事实上,我阅读了以下文件:
不是很明白,有大神知道怎么弄吗?
还有,这是什么意思:
注意:在调用 SMLoginItemSetEnabled 函数之前,首先通过使用帮助应用程序包的 URL 调用 LSRegisterURL 函数向 Launch Services 注册。
有没有关于如何使用LSRegisterURL和SMLoginItemSetEnabled的示例?
+ (void)startHelper {
NSURL *helperURL = [[[NSBundle mainBundle] bundleURL] URLByAppendingPathComponent:@"Contents/Library/LoginItems/YourHelper.app" isDirectory:YES];
OSStatus status = LSRegisterURL((CFURLRef)helperURL, YES);
if (status != noErr) {
NSLog(@"Failed to LSRegisterURL '%@': %jd", helperURL, (intmax_t)status);
}
Boolean success = SMLoginItemSetEnabled(CFSTR("com.yourcompany.helper-CFBundleIdentifier-here"), YES);
if (!success) {
NSLog(@"Failed to start Helper");
}
}
请注意,Helper 必须与主应用程序一起打包在“Contents/Library/LoginItems”目录中。您将需要在构建期间创建它并在那里复制帮助程序。
我找到了一个方便的链接:
http://www.delitestudio.com/2011/10/25/start-dockless-apps-at-login-with-app-sandbox-enabled/
编辑:遗憾的是这个链接不再有效。也许有人可以提出一个更好的选择......
如果有用的话,这是一个在沙盒环境中注册登录项的好教程(我们最终都需要!)。重要的是,令人讨厌的是,您必须将构建的主应用程序复制到 Applications 文件夹,并且不要做我所做的事情,即忘记将 helper-app 沙箱化并Application is agent (UIElement)
在 helper 的 plist 中添加一行以TRUE
获取值. NSLog
现在,Console 是您的老式调试朋友。
...只需要弄清楚当它们都被沙盒化时如何让帮助应用程序启动主应用程序.....编辑:发现这个问题: Cocoa: Sandbox entitlement to launch another application
我从来没用过LSRegisterURL
,我可以回答第一个问题:要设置LSUIElement
位,您只需打开 .plist 并添加行“Application is agent (UIElement)”,然后将值设置为 TRUE。
基本上你必须看看Launch Services
which 只是一个包装器,你可以通过在终端中launchd
查看来检查它。man launchd