what cause error NSNetServicesErrorCode = "-72000"?

7k views Asked by At

i create a simple browser that can load a local file using UIWebview. At first,when i try to preview a html file, the uiwebview can load the source file and preview it. But after i minimize the app (the app enter background), and then open the app again, i've got this error :

Error Dict: {
    NSNetServicesErrorCode = "-72000";
    NSNetServicesErrorDomain = 10;
}

and after that, the uiwebview can not load the source file, when i log the error in (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error, it shows this message :

Error Domain=NSURLErrorDomain Code=-1004 "Could not connect to the server." UserInfo=0x53d610 {NSErrorFailingURLStringKey=http://localhost:9898/local/a.html?83C66B33-874C-41A7-BBF5-78D1615512DF, NSErrorFailingURLKey=http://localhost:9898/local/a.html?83C66B33-874C-41A7-BBF5-78D1615512DF, NSLocalizedDescription=Could not connect to the server., NSUnderlyingError=0x5ccaa0 "Could not connect to the server."}

the app isn't crash, but the spinning indicator is never stop.

could somebody tell me what cause this case? and how to solved it?

Thank you :)

3

There are 3 answers

1
possen On

Sergiu Todirascu's comment in the question solved it for me. The Mac Sandbox was causing this, I had to turn on Networking, in my case Incoming and Outgoing network checkboxes, in the entitlements tab. Creating an answer so it is more easy to see.

1
Sean Michael Dorian On

If you look inside the NSNetServices header, you'll see the following enum that explains each error:

typedef NS_ENUM(NSInteger, NSNetServicesError) {

/* An unknown error occured during resolution or publication.
*/
    NSNetServicesUnknownError = -72000L,

/* An NSNetService with the same domain, type and name was already present when the publication request was made.
*/
    NSNetServicesCollisionError = -72001L,

/* The NSNetService was not found when a resolution request was made.
*/
    NSNetServicesNotFoundError  = -72002L,

/* A publication or resolution request was sent to an NSNetService instance which was already published or a search request was made of an NSNetServiceBrowser instance which was already searching.
*/
    NSNetServicesActivityInProgress = -72003L,

/* An required argument was not provided when initializing the NSNetService instance.
*/
    NSNetServicesBadArgumentError = -72004L,

/* The operation being performed by the NSNetService or NSNetServiceBrowser instance was cancelled.
*/
    NSNetServicesCancelledError = -72005L,

/* An invalid argument was provided when initializing the NSNetService instance or starting a search with an NSNetServiceBrowser instance.
*/
    NSNetServicesInvalidError = -72006L,

/* Resolution of an NSNetService instance failed because the timeout was reached.
*/
    NSNetServicesTimeoutError = -72007L,

};

You're getting a service collision error, which means that a net service with the same domain, type, and name are already publishing their service on your network.

In general, I always consult the header file for error codes. They're nearly always assigned by an enum value, and the enum usually has a much more descriptive name than the number used.

6
c2h5oh On

The problem seems to be the host you are trying to connect to: http://localhost:9898/local/[..]

Localhost on your computer is your computer, localhost on your ipad is your ipad - for testing use resolvable domain name or ip address.