2012-10-24 20 views
0

我無法理解在主頁按鈕被按下後幾秒鐘拋出的異常。iPhone NSDestinationInvalidException在NSURLConnection處於活動狀態時點擊主頁按鈕

*** Terminating app due to uncaught exception 'NSDestinationInvalidException', reason: '*** -[GMMLoader performSelector:onThread:withObject:waitUntilDone:modes:]: target thread exited while waiting for the perform'

我編程的應用程序,其使用一個web服務加載不同的數據集。 webservice被添加到operationQueue。

WebService* op = 
    [[WebService alloc] initWithSearchString:self.searchBar.text 
     notificationCenter:self.progressNotification]; 
    [self.queue addOperation:op]; 

[op addObserver:self 
     forKeyPath:@"isFinished" 
      options:NSKeyValueObservingOptionNew 
      context:NULL]; 

[op release]; 

在Web服務的-(void) start消息,我呼籲在主線程來執行這個起始選擇,能夠與UI交互。

- (void)start 
{ 
    if (![NSThread isMainThread]){ 

     [self performSelectorOnMainThread:@selector(start) withObject:nil waitUntilDone:YES]; 
     return; 
    } 
    ... 
} 

所有這一切工作正常,但是當我按下home鍵,而Web服務是活動的,我得到的提到例外。

我的猜測是,主線程在主頁按鈕被按下後停止(是這樣嗎?)。因此,當前正在運行的操作不再更新/有效。

我試着收聽事件UIApplicationWillResignActiveNotification,通過取消或掛起隊列中的操作來對主頁按鈕按下作出反應。然而這並沒有幫助。我猜對了,這個錯誤是因爲主線程暫停而發生的嗎? 我還能如何設法停止/取消當前的webservice線程?

預先感謝您 Zerd

回答

0

我發現的錯誤。 事實證明,這不是web服務本身的問題,而是一個geolocator,它創建並啓動兩次。

由於這個原因,某種殭屍線程被創建,永遠不會停止。

相關問題