简体   繁体   中英

Is there some way to get a string description of CFStreamError?

I am using an API which has handed me a CFStreamError (which is supposedly deprecated, but Apple themselves obviously don't care.)

I know some of the values and I could certainly write multiple nested switch statements to convert all the values I know into strings, but there will be values I don't know.

Isn't there some convenient way to get an error message out? I don't care whether it's localised or not because it will only end up in our logs anyway.

The 'old', pre- NSError way of handling errors usually involved return codes that were supposed to be used internally by the application (ie the developer) and not for presenting to the user.

With newer APIs the NSError returned actually contains information that an be presented to the user (if appropriate).

As for the CFStreamError -
There's an entry on CocoaDev on making CFStreamError human-readable:

http://cocoadev.com/CFStreamErrorCodes

Basically it involves manually checking the various error domains from CFStream Error Domain Constants .

A bit more information from Developer Technical Support can be found in this post on the Macnetworkprog mailing list.

This works for POSIX domain errors:

            if (err.domain == kCFStreamErrorDomainPOSIX) {
                DLog("POSIX err: %s", strerror(err.error));
            } else {
                DLog("domain: %d, value: %d", err.domain, err.error);
            }

Eg:

2020-01-31 09:58:02.996603-0800 blah void CFWriteStreamCB(CFWriteStreamRef _Null_unspecified, CFStreamEventType, void * _Null_unspecified):26 POSIX err: Operation timed out

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM