objective-c - 如何为 Mac App 创建辅助应用程序以在用户登录时启动它?

标签 objective-c macos autologin

最佳答案

+ (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”目录中。您将需要在构建过程中创建它并将助手复制到那里。

关于objective-c - 如何为 Mac App 创建辅助应用程序以在用户登录时启动它?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7436318/

相关文章:

iphone - 如何在 iPhone 上添加全屏 iAd?

ios - 如何验证电子邮件地址

macos - NSTextView中的GlyphRange和CharacterRange有什么区别?

php - IIS Server 7.0 仅在 Firefox (MacOs) 上返回 401 未经授权的访问

linux - 在 OpenSUSE 中登录后但在 X 之前运行脚本/应用程序

javascript - 如何使用cookies构建登录页面?

Python登录https网站(epex spot)使用requests下载文件

objective-c - NSView drawRect 干扰 subview ?

ios - 如何删除带有圆角和边框宽度的 UIImageView 上的黑边?

objective-c - 与图像或 key 数据库进行图像比较