2013-01-17 249 views
0

每當遇到連接問題,在2G等連接速度慢,我的應用程序崩潰,並顯示以下日誌:應用程序崩潰的互聯網連接速度較慢

enter image description here

我可以從日誌中得到的是,它的sendSynchronousRequest方法崩潰NSURLConnection。我怎麼知道問題到底是什麼,我該如何解決? 我已經把蘋果提供的Reachability方法,但返回YES來互聯網可達性和主機可達性。只是因特網連接速度很慢。 快速連接(Wifi),它工作得很好。

編輯:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 
[window setFrame:[[UIScreen mainScreen] bounds]]; 
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; 
//singleton 
u=[[U5 alloc]init]; 
m_tUSyncPersistableConfig = [[USyncPersistableConfig alloc] init] ;  
    m_commonObj = [[CommonClass alloc] init] ; 
u.m_tUSyncPersistableConfig=m_tUSyncPersistableConfig; 
    u.commonObj = m_commonObj; 


//register for push notifications 
    [[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)]; 

//load persisting data : from sqlite database 
[u loadPreferences:m_tUSyncPersistableConfig]; 


window.rootViewController = tabBarController; 

[window makeKeyAndVisible]; 


    if (![[NSUserDefaults standardUserDefaults] boolForKey:@"HasLaunchedOnce"]) { 
     //first launch//setting some values 
    }else { 
     //not first launch 
} 

    if (![[NSUserDefaults standardUserDefaults] boolForKey:@"HasLaunchedOnce"] || [u.m_tUSyncPersistableConfig.mUserName isEqualToString:@""] || !u.m_tUSyncPersistableConfig.mUserName) 
{ 
    // This is the first launch ever 
    //present login page 

} 
else 
{ 
    // app already launched 
    [[u commonObj] performSelectorInBackground:@selector(getAccountInfo) withObject:nil]; 
} 

return YES; 
} 
+0

你有沒有檢查:-http://stackoverflow.com/questions/10288133/ios-app-gets-sigkill-due-to-slow-network-connection –

+0

這並不能解決我的問題。我打電話在後臺線程中的所有連接方法,沒有在主線程 –

+0

http://stackoverflow.com/questions/10249377/nsurlconnection-delegate-methods-on-background-thread –

回答

1

我會強烈建議從同步NSURLConnection的Web請求移開。這不是Apple推薦的,被認爲是糟糕的設計。我建議轉向異步請求 - 它可能會迴避你的問題,並且你可以用NSURLConnection委託方法處理錯誤。

+0

我正在做的是在後臺線程中調用一個方法,該方法發送同步請求,因爲我需要響應那裏和那裏。如果我使用異步API,我不知道什麼時候得到響應,整個設計就會崩潰。不是嗎? –

1

在後臺線程中運行同步請求通常很好。

但是,崩潰報告顯示同步請求正在主線程上運行。所以至少有一個位置不在後臺線程中運行。在主線程中,它會阻止用戶界面,並且iOS看門狗進程會注意到這一點,並在啓動時關閉應用程序。

因此,請確保您永遠不會在主線程中使用同步請求!

你說你正在這樣做,但也許你做錯了。顯示實際調用連接方法的代碼。如果您使用的是崩潰報告,它還會在線程0堆棧跟蹤的第8到10幀中顯示這些位置。

相關問題