解决方法
+ (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”目录中.您将需要在构建期间创建它,并在那里复制帮助器.