2010-12-22 25 views
4

我使用Apple提供的可達性示例代碼來檢查網絡連接並獲取變更通知(Reachability Sample code)。可達性崩潰API

我看了一下我的應用程序的一些崩潰鎖。看起來有些崩潰是由於Reachability/SystemConfiguration Reachablity API的原因(見下文)。 SCNetworkReachabilityGetFlags僅用於Apple提供的Reachability類。或者我誤解了崩潰日誌?

Exception Type: EXC_CRASH (SIGABRT) 
Exception Codes: 0x00000000, 0x00000000 
Crashed Thread: 0 

Thread 0 Crashed: 
0 libSystem.B.dylib    0x00000e70 mach_msg_trap + 20 
1 libSystem.B.dylib    0x00003354 mach_msg + 60 
2 SystemConfiguration   0x0001f480 configopen + 168 
3 SystemConfiguration   0x00004d08 SCDynamicStoreCreateWithOptions + 272 
4 SystemConfiguration   0x00004e54 SCDynamicStoreCreate + 24 
5 SystemConfiguration   0x00015244 updateReachabilityStoreInfo + 152 
6 SystemConfiguration   0x00016f04 updateCommCenterStatus + 32 
7 SystemConfiguration   0x00017678 checkAddress + 1368 
8 SystemConfiguration   0x0001a260 __SCNetworkReachabilityGetFlags + 1992 
9 SystemConfiguration   0x0001b00c rlsPerform + 132 
10 CoreFoundation     0x00058266 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 8 
11 CoreFoundation     0x00028692 __CFRunLoopDoSources0 + 214 
12 CoreFoundation     0x00027f62 __CFRunLoopRun + 258 
13 CoreFoundation     0x00027d74 CFRunLoopRunSpecific + 220 
14 CoreFoundation     0x00027c82 CFRunLoopRunInMode + 54 
15 GraphicsServices    0x00004e84 GSEventRunModal + 188 
16 UIKit       0x00004f8c -[UIApplication _run] + 564 
17 UIKit       0x000024cc UIApplicationMain + 964 
18 MyApp       0x0000f80c main (main.m:21) 
19 MyApp       0x0000f77c start + 44 

回答

3

我發現最好只嘗試打開網絡連接。如果失敗,則設置一個標誌以嘗試後者並避免「可達性」。即使啓動時「可達性」通過,它也可以在任何時候淡入淡出。

+0

我同意這一點,但你可以使用可達性「幫助」;例如,讓用戶知道他們在請求失敗時可能未連接到互聯網。 – 2012-12-10 02:23:36

0

可達性是Apple最差的示例代碼示例之一。

雖然它擅長通知網絡連接,但它在指示主機是否可達時相當差[讀:無望]。

您也可以直接ping主機,並在超時時捕獲故障。

0

只是在Reachability.m中註釋掉以下行,如果它在那裏。

[super init]; 
0

在第一個視圖控制器中使用它。在模態視圖或其他派生視圖中使用它時很容易陷入麻煩。