nsurlconnection

Asynchronous NSURLConnection on separate thread fails to call delegate methods

て烟熏妆下的殇ゞ 提交于 2019-12-04 22:20:56
问题 I am running a NSURLConnection on a separate thread (I am aware that it is asynchronous and works when running on the main thread), but it is not making delegate calls even when I pass the parent thread as the delegate. Does anyone know how to do this? Code: -(void)startConnectionWithUrlPath:(NSString*)URLpath { //initiates the download connection - setup NSURL *myURL = [[NSURL alloc] initWithString:URLpath]; myURLRequest = [NSMutableURLRequest requestWithURL:myURL cachePolicy

optimising multiple asynchronous image downloads in iOS

一个人想着一个人 提交于 2019-12-04 19:36:37
I want to download a lot of pictures from the server. How can I do this as fast as possible? Currently I am using: UIImage* myImage = [UIImage imageWithData: [NSData dataWithContentsOfURL: [NSURL URLWithString: @"http://example.com/image.jpg"]]]; It is painfully slow. Is there any speed increase in downloading multiple images at the same time (asynchronously), and if so how many is too many? You won't get a definitive answer to the optimal number of connections, because there is none. It just depends on several variables such as bandwidth, image size or your own patience. You need to measure

how to convert php return NSData into NSDictionary

风格不统一 提交于 2019-12-04 19:33:21
HI, i am creating an login screen to my iphone application. i am sending the username and password to php using NSURLConnection method. i can successfully send login details to php. My php page returning status values based on the login details. (status =OK / Fail , redirectionUrl= http://www.balalaa.com ) In DidReceiveData method if i convert the NSData into string i am getting following string for successful login "STATUS=OK&url= http://www.balalaa.com ". Is there any way to fetch the values of STATUS and url, without using NSPredict. Is there any other way to conert the NSData into

Asynchronous POST to server

∥☆過路亽.° 提交于 2019-12-04 19:16:35
The goal is to do a simple username/password authentication by querying a database. Until the connection is working decently my php destination file simply has following code: echo "Posted: " . $_POST['email']; The code to do this synchronously is this: NSString *post = [[NSString alloc] initWithFormat:@"email=%@&password=%@", self.email.text, ..]; // .. simplified keychainItem NSData *postEncoded = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:NO]; NSString *postLength = [NSString stringWithFormat:@"%d", [postEncoded length]]; NSURL *url = [NSURL URLWithString:@"http:/

Handling a NSURLRequest with timeout when using delegate

大城市里の小女人 提交于 2019-12-04 18:11:30
问题 I'm using a NSMutableURLRequest to connect to a web site to get a JSON response. I'm doing so by generating the request, and then using NSURLConnection with a delegate of self to handle the async connection. I've implemented all the normal delegate methods: - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data - (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error - (void)connectionDidFinishLoading:(NSURLConnection *)connection All works

When is a NSURLResponse not a NSHTTPURLResponse?

人盡茶涼 提交于 2019-12-04 17:24:42
问题 I've seen a lot of code, including Apple's SimpleURLConnections sample, that simply cast any NSURLResponse to a NSHTTPURLResponse. If it is always a NSHTTPURLResponse why do the NSURLConnections not return NSHTTPURLResponse? I'm worried that if I simply downcast the response, I'm introducing buggy code. For instance, is it OK to do this without checking isKindOfClass? - (NSURLRequest *)connection:(NSURLConnection *)connection willSendRequest:(NSURLRequest *)request redirectResponse:

AFNetworking Enable GZIP

为君一笑 提交于 2019-12-04 16:51:14
问题 I am looking on the AFNetworking site that GZIP compression is supported " Gzip decompression from server responses is already built into AFNetworking, as NSURLConnection will automatically decompress responses with the Content-Encoding: gzip HTTP header. " - AFNetworking FAQ How do I enable GZIP compression so I can pull data from the server compressed or is it already defaulting to this? Thanks! 回答1: AFAIK NSURLConnection uses gzip decompresson by default and AFNetworking builds on the top

Domain=NSURLErrorDomain Code=-1001 “The operation couldn’t be completed. (NSURLErrorDomain error -1001.)”

老子叫甜甜 提交于 2019-12-04 16:41:33
my program is write for upload the picture from the cam,sample code below: #define WEBSERVICE_URL @"http://192.168.0.104/upload.php" - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { [picker dismissViewControllerAnimated:YES completion:^{ UIImage *selectedImage = [info objectForKey:UIImagePickerControllerOriginalImage]; NSData *imageData = UIImagePNGRepresentation(selectedImage); NSMutableURLRequest *request = [[AFHTTPRequestSerializer serializer] multipartFormRequestWithMethod:@"POST" URLString:WEBSERVICE_URL parameters:nil

how download file with NSURLConnection in storyboard

谁都会走 提交于 2019-12-04 16:03:45
I am a noob in NSURLConnection . I have searched Google and found this site but I dont understand about it. My friends please explain the code that I have downloaded from url in Document folder. This is my code : - (void)viewDidLoad { [super viewDidLoad]; NSURL *url =[NSURL URLWithString:@"http://cdn.arstechnica.net/wp-content/uploads/2012/09/iphone5-intro.jpg"]; NSURLRequest *request = [NSURLRequest requestWithURL:url]; NSURLConnection *con = [[NSURLConnection alloc]initWithRequest:request delegate:self]; [con start];} - (void)connection:(NSURLConnection *)connection didReceiveResponse:

NSURLConnection Leaks — Why?

时间秒杀一切 提交于 2019-12-04 16:03:22
问题 NSURLConnection *connection is a property of the class @property (nonatomic, retain) NSURLConnection *connection; Instruments is reporting that I'm leaking an NSURLConnection object in the second line of the code below. NSURLRequest *request = [[NSURLRequest alloc] initWithURL:_url]; self.connection = [[NSURLConnection alloc] initWithRequest:request delegate:self]; [request release]; In the didFinishLoading and didFinishWithError delegate selectors, I'm releasing the connection and setting to