5

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 :)

R. Dewi
  • 4,141
  • 9
  • 41
  • 66

3 Answers3

7

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.

2

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.

c2h5oh
  • 4,492
  • 2
  • 23
  • 30
  • I get the same error code, while connecting to some local IP. Or rather push my Server to the local network and access it via 192.x.y.z. Therefor the bounty. – Bersaelor Jun 29 '12 at 13:20
  • Are you sure ipad can access that url? try typing it in ipads browser address bar just to be certain. – c2h5oh Jun 29 '12 at 15:22
  • I can't access it from any device in the local network, once this error occurs. Usually I can publish the web service without problems, then it's accessible from any device (iPad, Macbook, Android Phone, Windows PC, whatever). But sometimes I get this error and was interested to know what the error code is trying to tell me. – Bersaelor Jun 29 '12 at 15:54
  • If you can't access it then the problem is server-side. Error code -72000 is "Unknown error", so all it tells you is that is isn't any of the usual stuff, but doesn't go into detail. – c2h5oh Jun 29 '12 at 16:42
  • Yes, of course it's server-side thats the point. The iPhone is serving the web-page to devices in the local network. I'm publishing the server and sometimes, while publishing I get the error the question-asker had too :/ – Bersaelor Jun 29 '12 at 16:59
  • As I said this error message gives you virtually no info as it is described in docs as "unknown error", so it's "I can't connect and I don't even know why, WTF" and that sadly is the most precise answer here. – c2h5oh Jun 29 '12 at 17:50
0

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.

possen
  • 8,596
  • 2
  • 39
  • 48