13

事实上,我阅读了以下文件:

应用程序可以包含一个帮助应用程序作为完整的应用程序包,存储在 Contents/Library/LoginItems 目录中的主应用程序包内。在帮助应用程序包的 Info.plist 文件中设置 LSUIElement 或 LSBackgroundOnly 键。

不是很明白,有大神知道怎么弄吗?

还有,这是什么意思:

注意:在调用 SMLoginItemSetEnabled 函数之前,首先通过使用帮助应用程序包的 URL 调用 LSRegisterURL 函数向 Launch Services 注册。

有没有关于如何使用LSRegisterURLSMLoginItemSetEnabled的示例?

4

4 回答 4

9
+ (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”目录中。您将需要在构建期间创建它并在那里复制帮助程序。

于 2011-11-15T23:29:11.147 回答
2

我找到了一个方便的链接:

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

于 2012-05-30T21:48:54.097 回答
-1

我从来没用过LSRegisterURL,我可以回答第一个问题:要设置LSUIElement位,您只需打开 .plist 并添加行“Application is agent (UIElement)”,然后将值设置为 TRUE。

于 2011-09-15T19:57:42.003 回答
-2

基本上你必须看看Launch Serviceswhich 只是一个包装器,你可以通过在终端中launchd查看来检查它。man launchd

或者在 SO How do you make your App open at login?看看这个问题?

于 2011-09-15T20:58:18.010 回答