如何为Mac App创建助手应用程序以在用户登录时启动它? [英] How to create a helper application for Mac App to start it on user login?

查看:94
本文介绍了如何为Mac App创建助手应用程序以在用户登录时启动它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

In fact, I read the following document:

我不太了解,有人知道怎么做吗?

I don't quite understand it, anyone knows how to do?

还有什么意思:

是否有关于如何使用 LSRegisterURL SMLoginItemSetEnabled 的示例?

is there any example about how to use LSRegisterURL and 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"目录中.您将需要在构建过程中创建它,并在其中复制帮助程序.

Note that the Helper must be packaged with the main app in the "Contents/Library/LoginItems" directory. You will need to create it during the build and copy the helper there.

这篇关于如何为Mac App创建助手应用程序以在用户登录时启动它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆