应用程序崩溃的互联网连接速度较慢
每当遇到连接问题,在2G等连接速度慢,我的应用程序崩溃,并显示以下日志:应用程序崩溃的互联网连接速度较慢
我可以从日志中得到的是,它的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;
}
我会强烈建议从同步NSURLConnection的Web请求移开。这不是Apple推荐的,被认为是糟糕的设计。我建议转向异步请求 - 它可能会回避你的问题,并且你可以用NSURLConnection委托方法处理错误。
我正在做的是在后台线程中调用一个方法,该方法发送同步请求,因为我需要响应那里和那里。如果我使用异步API,我不知道什么时候得到响应,整个设计就会崩溃。不是吗? –
在后台线程中运行同步请求通常很好。
但是,崩溃报告显示同步请求正在主线程上运行。所以至少有一个位置不在后台线程中运行。在主线程中,它会阻止用户界面,并且iOS看门狗进程会注意到这一点,并在启动时关闭应用程序。
因此,请确保您永远不会在主线程中使用同步请求!
你说你正在这样做,但也许你做错了。显示实际调用连接方法的代码。如果您使用的是崩溃报告,它还会在线程0堆栈跟踪的第8到10帧中显示这些位置。
你有没有检查:-http://*.com/questions/10288133/ios-app-gets-sigkill-due-to-slow-network-connection –
这并不能解决我的问题。我打电话在后台线程中的所有连接方法,没有在主线程 –
http://*.com/questions/10249377/nsurlconnection-delegate-methods-on-background-thread –