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

前端 未结 19 1454
执念已碎
执念已碎 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条回答
  • 2020-12-05 02:07

    Use the OSX calc program. Select "programmer" mode in presentation menu. Then type your code in decimal représentation. Then choose the "ascii" button and the calc will show you the 4 char translation such as "!init", "!cat", etc...

    0 讨论(0)
  • 2020-12-05 02:10

    This is available on macOS and for iOS from 11.3 and above.

    I know this is an old post, but I was reading the apple docs in a section related to keychains. They mention a method that is used to convert OSStatus errors into something readable.

    SecCopyErrorMessageString

    Returns a string explaining the meaning of a security result code.

    SecCopyErrorMessageString (OSStatus status, void* reserved );

    Useage:

    NSString* ErrMsg = (__bridge_transfer NSString *) SecCopyErrorMessageString(theOSStatusError, NULL);
    

    It worked for me with my keychain OSStatus errors. Does it work for you? You will need Security.Framework added to your project to use this method.

    0 讨论(0)
  • 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 <Foundation/Foundation.h>
    #import <CoreServices/CoreServices.h>
    
    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)
    
    0 讨论(0)
  • 2020-12-05 02:12

    Most time maybe you just need to find the error code in the .h files

    I just made a python script to find the code (when you debug/print a osstatus code)

    https://github.com/sprhawk/MyGist/blob/master/tools/find_osstatus_error.py

    0 讨论(0)
  • 2020-12-05 02:15

    I combined a few answers. Actually I were looking something like „throw errorForStatusCode(status)”. But in the end achieved:

        guard status == errSecSuccess else {
            throw  NSError(domain: NSOSStatusErrorDomain, code: Int(status), userInfo: [NSLocalizedDescriptionKey: SecCopyErrorMessageString(status, nil) ?? "Undefined error"])
        }
    

    SecCopyErrorMessageString is available from iOS 11.3 https://developer.apple.com/documentation/security/1542001-security_framework_result_codes

    0 讨论(0)
  • 2020-12-05 02:15

    This is not a direct answer to OP's question, but I think it will be useful to whoever is concerned with these OSStatus return codes:

    Search for keyword "Result Codes" in Xcode documentation (Organizer) and we get a more or less categorized return codes documentation sections in the "System Guides" result.

    If you just need to use some codes directly in your custom functions, they are very helpful.

    0 讨论(0)
提交回复
热议问题