码迷,mamicode.com
首页 > 移动开发 > 详细

iOS nsurlconnection 回调方法无效的分析!

时间:2015-01-22 17:28:27      阅读:182      评论:0      收藏:0      [点我收藏+]

标签:

 dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:urlStr] cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:CONNECTIONT_TIMEOUT];
        NSString *encodedStr = [body stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
        NSData *sendData = [encodedStr dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES];
        NSString *dataLengthStr =[NSString stringWithFormat:@"%lu",(unsigned long)[sendData length]];
        [request setValue:dataLengthStr forHTTPHeaderField:@"Content-Length"];
        [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
        [request setHTTPMethod:@"POST"];
        [request setHTTPBody:sendData];
        self.connection = [NSURLConnection connectionWithRequest:request delegate:self];
    });

这是一个在主线程中执行的代码,执行结果有问题,无法收到网络回掉。

分析待续。。。

需要研究为什么connection不能阻止线程结束!什么东西能阻止??

iOS nsurlconnection 回调方法无效的分析!

标签:

原文地址:http://www.cnblogs.com/breezemist/p/4241755.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!