1

Good day, i want to set my application default for a file type with coocoa framework. Now i write next code:

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;
}

but after execution it get error 50. What i do wrongly?

Ben Lu
  • 2,982
  • 4
  • 31
  • 54
Topilski Alexandr
  • 669
  • 1
  • 12
  • 34

1 Answers1

4

".txt" is a file extension, not a uniform type identifier (UTI).

You need to use a proper UTI, e.g. CFSTR("public.plain-text")

User Guillaume wrote a nice little function to convert file extensions to UTI's, you can see it here, named "UTIforFileExtension:" (and you should upvote his answer if it helps you :-)

Community
  • 1
  • 1
Michael Dautermann
  • 88,797
  • 17
  • 166
  • 215