我在執行NSURLConnection委託方法connectionDidFinishLoading時收到錯誤。有趣的是,它可以在模擬器上運行,但它在物理設備上崩潰。更有趣的是它崩潰,只有當這種操作序列完成後,在connectionDidFinishLoading中收到錯誤,EXC_BAD_ACCESS
- 運行應用程序
- 顯示資料Tweet! (真棒)
- 按Home鍵
- 雙擊Home鍵
- 強制退出應用程序
- 再次打開應用
- CRASHED !!!!! (:()...保持崩潰,直到你重新啓動手機
錯誤日誌:
Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_INVALID_ADDRESS at 0xa0000008
Crashed Thread: 0
Thread 0 name: Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0 libobjc.A.dylib 0x321befbc 0x321bb000 + 16316
1 Tittle-Tattle 0x0002cf10 -[MapViewController connectionDidFinishLoading:] (MapViewController.m:108)
2 Foundation 0x3316bc32 0x330a5000 + 814130
3 Foundation 0x330c36e2 0x330a5000 + 124642
4 Foundation 0x330c36ac 0x330a5000 + 124588
5 Foundation 0x330c35ce 0x330a5000 + 124366
6 CFNetwork 0x35e7689e 0x35e67000 + 63646
7 CFNetwork 0x35e6b53e 0x35e67000 + 17726
8 CFNetwork 0x35e6b632 0x35e67000 + 17970
9 CFNetwork 0x35e6b23c 0x35e67000 + 16956
10 CFNetwork 0x35e6b172 0x35e67000 + 16754
11 CoreFoundation 0x34176afc 0x340e9000 + 580348
12 CoreFoundation 0x341762c8 0x340e9000 + 578248
13 CoreFoundation 0x3417506e 0x340e9000 + 573550
14 CoreFoundation 0x340f84d6 0x340e9000 + 62678
15 CoreFoundation 0x340f839e 0x340e9000 + 62366
16 GraphicsServices 0x3254dfc6 0x3254a000 + 16326
17 UIKit 0x3734e73c 0x3731d000 + 202556
18 Tittle-Tattle 0x000200e0 main (main.m:16)
19 Tittle-Tattle 0x00020084 start + 32
CODE:
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
[urlConnection cancel];
[urlConnection release];
NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
//Since we got new fresh data we shall put it in LatestLocationData entity in CoreData
[self insertLastKnownLocationDataIntoCoreDataWith:responseString];
//Test purpose only, See what we have got in CoreData
[self fetchLastKnownLocationDataFromCoreData];
NSDictionary *results = [responseString JSONValue];
placesNearBy = [results objectForKey:@"results"];
[responseString release];
[self dropNearByPlacesAnnotationsFrom:placesNearBy];
}
問:什麼可能是可能的原因是什麼?
類似的問題(!不是由我)以前提出的,但對這個問題沒有人回答說:Application not running in iOS 5
據我瞭解到目前爲止,只有EXE_BAD_ACCESS當您試圖訪問還沒有內存地址發生已被分配,或先前已分配但現在已被釋放。
修改回覆IN後評論:
嘿Firoze,這是怎麼了初始化NSURLConnection的
urlConnection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
@FirozeLafeer嘿夥計!我已經添加了init方法。有問題:)謝謝。我在那裏發佈NSString,因爲我是alloc並且init是相同的函數。我想我應該釋放它是嗎?否則會泄漏 – doNotCheckMyBlog
responseData來自哪裏?無論它在哪裏創建,它都被保留下來了嗎? – coneybeare
@Brogrammer無視我對responseString的評論。沒關係,我沒有直接在那裏想。我錯過了那部分。 –