rou*_*tem 10

+ (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");
    }
}
Run Code Online (Sandbox Code Playgroud)

请注意,Helper必须与主要应用程序一起打包在"Contents/Library/LoginItems"目录中.您需要在构建期间创建它并在那里复制帮助程序.


Man*_*lio -1

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