gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-30 03:26:19 25 4
gpt4 key购买 nike

最佳答案

+ (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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com