2012-05-11 68 views
3

我創建了一個簡單的瀏覽器,可以使用UIWebview加載本地文件。起初,當我嘗試預覽一個html文件時,uiwebview可以加載源文件並預覽它。但之後,我最小化的應用程序(應用程序進入後臺),然後再次打開該應用程序中,我得到這個錯誤:什麼導致錯誤NSNetServicesErrorCode =「-72000」?

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

,並在這之後,一個UIWebView無法加載源文件,當我登錄在(void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error錯誤,它顯示了這個消息:

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."} 

的應用程序是不會崩潰,但紡紗指標永不停止。

有人可以告訴我是什麼原因導致這種情況?以及如何解決它?

謝謝:)

+0

你能告訴你如何初始化網頁視圖嗎? – sergio

+0

你可以發佈一些代碼嗎? – Hejazi

回答

2

的問題似乎是你試圖連接到主機:http://localhost:9898/local/[..]

本地主機計算機上的是您的計算機,本地主機上你的iPad是你的iPad - 用於測試使用可解析的域名或IP地址。

+0

當連接到一些本地IP時,我得到相同的錯誤代碼。或者將我的服務器推送到本地網絡並通過192.x.y.z訪問它。爲此,賞金。 – Bersaelor

+0

你確定ipad可以訪問該網址嗎?嘗試在iPad的瀏覽器地址欄中輸入,以確保它。 – c2h5oh

+0

一旦發生此錯誤,我無法從本地網絡中的任何設備訪問它。通常我可以毫無問題地發佈Web服務,然後可以從任何設備(iPad,Macbook,Android Phone,Windows PC等)訪問它。但是有時候我得到這個錯誤,並且很想知道錯誤代碼試圖告訴我什麼。 – Bersaelor

3

如果你看看NSNetServices水箱內,你會看到下面的枚舉解釋每個錯誤:

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, 

}; 

你得到一個服務衝突錯誤,這意味着相同的域網服務,類型和名稱已在您的網絡上發佈其服務。

通常,我總是查閱錯誤代碼的頭文件。它們幾乎總是由一個枚舉值分配的,枚舉通常具有比所使用的數字更多的描述性名稱。