新建一个single View Application的工程,再建一个类,专门用来实现HTTP请求数据的功能
如下,只写了一个函数实现异步调用
-(void) postDataInfo:(NSString*) nsPostVar:(NSString*)nsUrl:(NSString*)nsReferer
{
NSData *postData = [nsPostVar dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
[request setURL:[NSURL URLWithString:nsUrl]];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:nsReferer forHTTPHeaderField:@"Referer"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postData];
self.Info = [[NSURLConnection alloc] initWithRequest:request delegate:[AppDelegate App].viewController]; //异步处理,委托主View接受信息
}
主view中
//全部数据接收完毕时触发
- (void)connectionDidFinishLoading:(NSURLConnection *)aConn
{
NSLog(@"connectionDidFinishLoading");
}
另外新建了一个view,专门来显示数据
在这个viewController中,我新建了2个timer来调用 postDataInfo
如下
- (void)postWonMoney
{
[[AppDelegate App].viewController.pwebOperator postDataInfo:参数1:参数2:参数3];
}
/////////////////view显示的时候就执行这个timer
[NSTimer scheduledTimerWithTimeInterval:(1) target:self selector:@selector(responseInfoTimer) userInfo:nil repeats:YES];
- (void)responseInfoTimer{
[self postWonMoney];//此处调用可以成功,能得到HTTP请求的数据
//如果此处再设定一个定时器,如下
[NSTimer scheduledTimerWithTimeInterval:(5) target:self selector:@selector(responseInfoTimer2) userInfo:nil repeats:YES];
}
- (void)responseInfoTimer2{
[self postWonMoney];//此处调用不成功,能得到HTTP请求的数据
//程序执行完self.Info = [[NSURLConnection alloc] initWithRequest:request delegate:[AppDelegate App].viewController]; 就崩溃了
}
请问这是什么原因,为什么在第一个定时器那里执行是没有问题的呢
------最佳解决方案--------------------
崩溃后,命令行给出的提示信息是什么?
------其他解决方案--------------------
自己先顶一下先
------其他解决方案--------------------
不会吧,没有人知道啊
------其他解决方案--------------------
没有人知道吗
------其他解决方案--------------------
崩溃后程序调到这里
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
}
后面提示Thread 1:EXC_BREAKPOINT(code=EXC_I386_BPT,subcode=0x0)
命令行无任何提示
------其他解决方案--------------------