gpt4 book ai didi

objective-c - 如何在 Mac 操作系统上将应用程序设置为默认应用程序?

转载 作者:行者123 更新时间:2023-12-03 16:54:43 25 4
gpt4 key购买 nike

美好的一天,我想使用 coocoa 框架将我的应用程序设置为文件类型默认值。现在我编写下一个代码:

bool setappasdefualt()
{
OSStatus returnStatus = LSSetDefaultRoleHandlerForContentType(CFSTR(".txt"), kLSRolesAll, (CFStringRef) [[NSBundle mainBundle] bundleIdentifier]);
if (returnStatus != 0)
{
NSLog(@"Got an error when setting default application - %ld", returnStatus);
return false;
}
return true;
}

但执行后出现错误 50。我做错了什么?

最佳答案

.txt”是文件扩展名,而不是统一类型标识符 (UTI)。

您需要使用适当的 UTI,例如CFSTR("public.plain-text")

用户 Guillaume 编写了一个很好的小函数来将文件扩展名转换为 UTI,you can see it here, named "UTIforFileExtension:" (如果他的回答对你有帮助,你应该投票:-)

关于objective-c - 如何在 Mac 操作系统上将应用程序设置为默认应用程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14744974/

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