【发布时间】:2013-01-17 07:03:05
【问题描述】:
每当出现连接问题、2G 连接速度慢等情况时,我的应用都会崩溃并显示以下日志:
我可以从日志中得到的是,它在 NSURLConnection 的 sendSynchronousRequest 方法上崩溃。我怎么知道到底是什么问题,我该如何解决?
我使用了 Apple 提供的 Reachability 方法,但将 YES 返回到 Internet 可访问性和主机可访问性。只是互联网连接速度很慢。
在快速连接 (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在主线程上发送同步请求。你确定你没有错过任何一个? -
@NikitaP 当你从网络上得到响应时,你为什么不做这项工作,在
viewDidLoad中设置一个加载指示器或其他东西?
标签: iphone ios crash reachability internet-connection