我在 applicationDidBecomeActive 方法中从服务器获取数据。当网络连接速度太慢时,应用程序不断崩溃。我不知道如何处理这个问题。任何帮助将不胜感激。提前致谢。
NSString *post =[[NSString alloc] initWithFormat:@"=%@@=%@",myString,acMobileno];
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http:///?data=%@&no=%@",myString,acMobileno]];
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL:url];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setHTTPBody:postData];
NSError *error1 = [[NSError alloc] init];
NSHTTPURLResponse *response = nil;
NSData *urlData=[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error1];
NSString *string;
if ([response statusCode] >=200 && [response statusCode] <300)
{
string = [[NSString alloc] initWithData:urlData encoding:NSMacOSRomanStringEncoding];
}