nsurlconnection

NSURLConnection is run many times

房东的猫 提交于 2019-11-28 07:48:20
I connect asynchronously with server each 5 seconds. The URL is the same, but POST-body is changed each time. Now I create NSURL, NSURLRequest and NSURLConnection from the scratch each time. I think it'd be more effective to set connection once and just use that one further. I am a newbie and not sure if that possible. There is no mutable NSURLConnection, but may it's need to create NSURLConnection like: NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL: url]; NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self]; and change

Object-c/iOS :How to use ASynchronous to get a data from URL?

故事扮演 提交于 2019-11-28 07:43:46
My friend saw my code, a part is get a plist data from URL And he told me not to use Synchronous,Use ASynchronous But I don't know how to do ASynchronous in simple way This is the code I use in my program NSURL *theURL = [[NSURL alloc]initWithString:@"http://someurllink.php" ]; NSURLRequest *theRequest=[NSURLRequest requestWithURL:theURL cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0]; NSData *returnData = [NSURLConnection sendSynchronousRequest:theRequest returningResponse:nil error:nil]; NSString *listFile = [[NSString alloc] initWithData:returnData encoding

Determining Trust With NSURLConnection and NSURLProtectionSpace

放肆的年华 提交于 2019-11-28 07:37:21
I would like to ask a followup question to a previously posed question . I've got the code to create an NSURLRequest/Connection, run it and have the callback methods for authentication get called. Here's the specific code: - (BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace { return [protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust] || [protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodDefault]; } -(void)connection:(NSURLConnection *)connection

Is there any way to attach a NSDictionary of parameters to an NSURLRequest instead of manually making a string?

守給你的承諾、 提交于 2019-11-28 07:02:56
问题 AFNetworking allows you to add an NSDictionary of parameters to a request, and it will append them to the request. So if I wanted to do a GET request with ?q=8&home=8888 I'd just making an NSDictionary like @{@"q": @"8", @"home": @"8888"} very simply. Is there a way to do this with NSURLSession / NSURLConnection / NSURLRequest ? I know I can use NSJSONSerialization for appending JSON data, but what if I just want them as GET parameters in the URL? Should I just add a category? 回答1: You can do

Authentication with NSURLConnection sendAsynchronousRequest with completion handler

微笑、不失礼 提交于 2019-11-28 07:00:47
Generally I like to just "fire and forget" with NSURL's sendAsynchronousRequest class method using the completion handler block but it seems that might not be an option when authentication is needed. When using a completion handler style request like this: [NSURLConnection sendAsynchronousRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.mysite.com/"]] queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) { //Do Stuff }]; What is the proper way to handle authentication? Do I need to alloc and init the NSURLConnection

Upload image from iOS to PHP

不问归期 提交于 2019-11-28 06:48:58
问题 I'm trying to upload an image from my iOS App to my web server via PHP. Here is the following code: -(void)uploadImage { NSData *imageData = UIImageJPEGRepresentation(image, 0.8); //1 NSURLSessionConfiguration *config = [NSURLSessionConfiguration defaultSessionConfiguration]; //2 NSURLSession *defaultSession = [NSURLSession sessionWithConfiguration:config delegate:self delegateQueue:nil]; NSString *urlString = @"http://mywebserver.com/script.php"; NSMutableURLRequest *request = [

Create SSL connection using certificate

邮差的信 提交于 2019-11-28 06:39:15
I have ssl certificate (.cer) which was provided to me as file. I added it to bundle and want to use it communicating with server. I used apple provided code: - (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge{ DLog(@"didReceiveAuthenticationChallenge : %@",challenge); if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust]) { NSString *filePath = [[NSBundle mainBundle] pathForResource:@"certificate" ofType:@"cer"]; NSData *certData = [NSData dataWithContentsOfFile

NSURLConnection needs a NSRunLoop to execute?

有些话、适合烂在心里 提交于 2019-11-28 06:16:57
问题 I'm trying to fetch the contents of a URL from a method called connect. It reads its configuration settings and attempts to fetch the URL. It appears to need the run loop to execute. I though it would just execute once and be done. It seems that I don't need to have that run loop running for any reason other than to fetch this URL once, whenever connect is called. Is there a better way do do this? - (BOOL) connect { // read serverName and eventId from preferences NSMutableArray* preferences;

NSURLConnection NSURLRequest proxy for asynchronous web service calls

痞子三分冷 提交于 2019-11-28 06:07:00
I have multiple views which make the same NSURLRequest/NSURLConnection request . Ideally, in order to get some code reuse, I'd like to have some sort of a "proxy" which does all the underlying work of creating/executing the (asynchronous) request/connection, setting up all the delegate methods, etc., so I don't have to copy all those NSURLConnection delegate method handlers in each view. First of all, is this design approach reasonable? Second, how would I go about doing something like that? For a little background info, I attempted this and got it to "work", however, it doesn't appear to be

setKeepAliveTimeout and BackgroundTasks

懵懂的女人 提交于 2019-11-28 04:36:01
I've a big headache with the topic. I'm working on an application that needs to poll a webserver regularly, in order to check for new data. Based on the returned information, I wish to push a local notification to the user. I know that this approach is slightly different from the one depicted by Apple, in which a remote server makes the work, pushing a remote notification, based on APNS. However, there are many reasons for which i cannot take this approach in consideration. One for all, is the user authentication mechanism. The remote server, for security reasons, cannot take into account the