How do you convert an iPhone OSStatus code to something useful?

前端 未结 19 1520
执念已碎
执念已碎 2020-12-05 01:45

I am getting more than a little sick of this iPhone SDK and its documentation...

I am calling AudioConverterNew

in the documentation under Returns: it says \

19条回答
  •  -上瘾入骨i
    2020-12-05 02:11

    If you want to create a command line utility, for use during development and support, then you can still use the deprecated Carbon methods, even in 10.9 (Mavericks). You obviously can't use this in an app you are submitting to Apple for inclusion in the App Stores.

    #import 
    #import 
    
    int main(int argc, const char **argv)
    {
        @autoreleasepool {
            for (int i = 1; i < argc; i++) {
                char *endp;
                long value = strtol(argv[i], &endp, 10);
                if (*endp == '\0') {
                    printf("%10ld: %s (%s)\n",
                        value,
                        GetMacOSStatusCommentString((OSStatus)value),
                        GetMacOSStatusErrorString((OSStatus)value));
                } else {
                    fprintf(stderr, "Invalid OSStatus code '%s' ignored\n", argv[i]);
                }
            }
        }
    }
    

    Compile with:

    $ clang -fobjc-arc -o osstatus osstatus.m -framework Foundation -framework CoreServices
    

    copy it somewhere in your $PATH:

    $ cp osstatus ~/bin
    

    and feed it error codes from your log files or error reports:

    $ osstatus -47
       -47: File is busy (delete) (fBsyErr)
    

提交回复
热议问题