In many network-based applications, network-based errors occur that are not related to your application. However, most users may not know why the app failed. The Cfnetdiagnostics API gives you a quick and easy way to help users solve network problems.
If your app uses a Cfstream object, then call the cfnetdiagnosticcreatewithstreams function to create a network diagnostic reference (cfnetdiagnosticref). The Cfnetdiagnosticcreatewithstreams has an allocator that reads the stream and writes the stream as a parameter. If your app uses only read or write streams, the unused parameters are set to NULL.
If no stream exists, you can also create a network diagnostic reference directly from the URL. To do this, call the cfnetdiagnosticcreatewithurl function and pass an allocator, URL to cfurlref. It will return a network diagnostic reference for you to use.
In order to diagnose the problem through the Network diagnostic assistant, call the cfnetdiagnosticdiagnoseprobleminteractively function and pass the network diagnostic reference. Listing 6-1 shows how to use Cfnetdiagnostics to diagnose a stream implemented on a running loop.
Checklist 6-1 using the Cfnetdiagnostics API when a stream error occurs
Case kcfstreameventerroroccurred: cfnetdiagnosticref diagref = cfnetdiagnosticcreatewithstreams (NULL, Stream, NULL); (void) Cfnetdiagnosticdiagnoseprobleminteractively (diagref); Cfstreamerror error = Cfreadstreamgeterror (stream); ReportError (error); Cfreadstreamclose (stream); Cfrelease (stream); Break
Cfnetworkdiagnostics can also retrieve the status of the problem, rather than using the network diagnostic assistant. You can do this by calling cfnetdiagnosticcopynetworkstatuspassively. The function returns a constant such as kcfnetdiagnosticconnectionup or kcfnetdiagnosticconnectionindeterminate.
Official Original address:
https://developer.apple.com/library/ios/documentation/Networking/Conceptual/CFNetwork/UsingNetworkDiagnostics/ Usingnetworkdiagnostics.html#//apple_ref/doc/uid/tp30001132-ch7-sw1
Using Network Diagnostics (using the Web diagnostics)