What is the cause of the error NSNetServicesErrorCode = "-72000"?

I am creating a simple browser that can download a local file using UIWebview. First, when I try to view the html file, uiwebview can download the source file and view it. But after I hide the application (application enter background) and then open the application again, I have this error:

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

and after that, uiwebview cannot load the source file when I log an 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 application is not crashing, but the rotation indicator never stops.

Can someone tell me what the reason for this is? and how to solve it?

Thanks:)

+4
source share
2 answers

If you look inside the NSNetServices header, you will see the following listing 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 get a collision error with a service, which means that a network service with the same domain, type and name is already publishing its service on your network.

In general, I always refer to the header file for error codes. They are almost always assigned the value of an enumeration, and an enumeration usually has a much more descriptive name than the number used.

+4
source

It seems that the problem is with the host you are trying to connect to: http://localhost:9898/local/[..]

The local host on your computer is your computer, localhost on your ipad is your ipad - use a resolvable domain name or IP address for testing.

+2
source

Source: https://habr.com/ru/post/1411952/


All Articles