其实我看了下面的文档:
不太明白,谁知道怎么办?
还有,这是什么意思:
有没有关于如何使用 LSRegisterURL 和 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”目录中。您将需要在构建过程中创建它并将助手复制到那里。
关于objective-c - 如何为 Mac App 创建辅助应用程序以在用户登录时启动它?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7436318/