新建一个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]; 就崩溃了
}
请问这是什么原因,为什么在第一个定时器那里执行是没有问题的呢
如下,只写了一个函数实现异步调用
-(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]; 就崩溃了
}
请问这是什么原因,为什么在第一个定时器那里执行是没有问题的呢
解决方案 »
- 如何在才能在后台applicationDidEnterBackground长久运行
- 请教高人,如何建立通用框架 Universal Framework
- IOS创建线程问题
- cocos2d-iphone-0.99.5编译问题
- 为什么[NSThread exit]会报错:Thread 3 signal SIGABRT? 有完整 救命代码
- [求助]如何让手势不消费触摸事件 急急急!!
- IOS 横屏 启动画面看不到
- ios tableView
- 请问发布到哪个国家,在 itunesconnect中怎么选?
- win7x64+vmware11.1.0,安装OS X 10.10失败
- 关于PhoneGap环境配置问题
- 苹果的开发文档
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
}
后面提示Thread 1:EXC_BREAKPOINT(code=EXC_I386_BPT,subcode=0x0)
命令行无任何提示
self.Info = [[NSURLConnection alloc] initWithRequest:request delegate:[AppDelegate App].viewController];
在接收的函数
//全部数据接收完毕时触发
- (void)connectionDidFinishLoading:(NSURLConnection *)aConn
{
NSLog(@"connectionDidFinishLoading");
}没有执行的时候就报错了,是不是委托那里有问题,在TIMER里面再建立一个TIMER,然后第二个TIMER的执行函数里面去调用就会出问题,如果只是一个TIMER,然后在这个TIMER的执行函数里面去调用是没有问题的
self.Info = [[NSURLConnection alloc] initWithRequest:request delegate:[AppDelegate App].viewController];
在接收的函数
//全部数据接收完毕时触发
- (void)connectionDidFinishLoading:(NSURLConnection *)aConn
{
NSLog(@"connectionDidFinishLoading");
}没有执行的时候就报错了,是不是委托那里有问题,在TIMER里面再建立一个TIMER,然后第二个TIMER的执行函数里面去调用就会出问题,如果只是一个TIMER,然后在这个TIMER的执行函数里面去调用是没有问题的
需要输出更多的调试信息,参考:
http://stackoverflow.com/questions/5386160/how-to-enable-nszombie-in-xcode
http://stackoverflow.com/questions/2190227/how-do-i-set-up-nszombieenabled-in-xcode-4
http://blog.csdn.net/linzhiji/article/details/6771998
-[CFRunLoopTimer release]: message sent to deallocated instance 0x162ac330
建议赋值前先self.info调用一下cancel。
前辈能否再帮我看看这个显示的问题,多谢了,晚上来接贴
http://www.cocoachina.com/bbs/read.php?tid=112855&page=1#670884