標籤:
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 回調方法無效的分析!