nsurlconnection

Background task when apns received

安稳与你 提交于 2019-11-29 12:14:06
After reading APNS documentation, I have implemented apns into my app. Everything works fine, but I have a question. I don't know if it is possible, but I would like to do a task when my app is in background and I receive a apns notification. This is my dictionary inside the notification: aps = { alert = "message"; sound = "default"; }; If my app is in foreground, I execute this code: - (void)application:(UIApplication*)application didReceiveRemoteNotification:(NSDictionary*)userInfo { [HTTPConnection sendGetToUrl:[NSURL URLWithString:stringUrl]]; NSLog(@"Received notification: %@", userInfo);

iOS and SSL: Unable to validate self-signed server certificate

只愿长相守 提交于 2019-11-29 12:06:11
I'm fairly new to consuming webservices using SSL channel. After fairly good search I had found a way to perform SSL/HTTPS authentication using NSURLConnection delegate APIs. Following is the code snippet that does the actual authentication thing: - (void)connection:(NSURLConnection *)connection willSendRequestForAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge { [self printLogToConsole:@"Authenticating...."]; [self printLogToConsole:[NSString stringWithFormat:@"\n%@\n", [challenge description]]]; NSLog(@"\n\nserverTrust: %@\n", [[challenge protectionSpace] serverTrust]); /*

Loading NSData into a UIWebView

帅比萌擦擦* 提交于 2019-11-29 10:02:12
In my web browser, I am trying to load a UIWebView with NSData obtained from a NSURLConnection . When I try to load it into the UIWebView , instead of the site, it comes up with the HTML plain text. Here is my code: in viewDidLoad: NSURLRequest *request = [NSURLRequest requestWithURL: [NSURL URLWithString:@"http://www.msn.com"]]; [NSURLConnection connectionWithRequest: request delegate:self]; later in the code: -(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data { webdata = [NSMutableData dataWithData: data]; } -(void)connectionDidFinishLoading:(NSURLConnection *

iphone: secure restfull server \"The certificate for this server is invalid

耗尽温柔 提交于 2019-11-29 04:36:56
I am trying to consume secure restful service which gives error Error = Error Domain=NSURLErrorDomain Code=-1202 "The certificate for this server is invalid. You might be connecting to a server that is pretending to be “xxx.xxx.xxx.xxx” which could put your confidential information at risk." working on xCode 4.2, where is the mistake or any step missing. using following code RegisterUser.f @interface RegisterUser : UIViewController<UITextFieldDelegate, UIScrollViewDelegate, NSURLConnectionDelegate> RegisterUser.m - (IBAction)SubmitBtnAction:(id)sender { NSURL *url = [NSURL URLWithString:@

Uploading Large NSData to the Web

安稳与你 提交于 2019-11-29 04:10:53
问题 I'm currently working on an application that has to upload large files (mainly movies/videos) to the web. After reading what I can, I went the the approach of converting the movie to NSData and then including that as the NSURLConnection's HTTPBody . However, upon converting the movie (which was originally an ALAsset ) into NSData , I receive a memory warning and then a subsequent crash. I have no idea how I would go about uploading these types of large files, if that data just causes an

NSURLConnection on iOS doesn't try to cache objects larger than 50KB

爱⌒轻易说出口 提交于 2019-11-29 04:10:23
Despite Apple's documentation indicating otherwise , NSURLCache on iOS doesn't do any disk (flash) caching at all. You can subclass NSURLCache to change the behaviour of the fetch and store operations to use the disk (like SDURLCache does), but due to the following severe limitations of how the cache is used and implemented, this doesn't work as well as you'd expect: NSURLConnection doesn't even call storeCachedResponse:forRequest: for files over about 50KB (>= 52428 bytes, to be exact). This makes subclassing NSURLCache pointless for our use (200KB images), because it won't even get to the

how do I check an http request response status code from iOS?

萝らか妹 提交于 2019-11-29 04:09:38
I am sending an http request from iOS (iPad/iPhone) to my python google app engine server using the NSURLConnection and NSURLRequest classes. How do I read the response's status, i.e. the value set by app engine using response.set_status(200, message="Success") for instance? I'm not able to find where I can read these status codes once I receive the NSURLConnection's connectionDidFinishLoading delegate call on the client end. The connection:didReceiveResponse: delegate method is called when a response is received, which gives you an NSURLResponse to play with. If you've made an HTTP request,

NSURLConnection blocking wrapper implemented with semaphores [closed]

戏子无情 提交于 2019-11-29 03:51:03
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 6 years ago . For my most recent project, I stumbled across the need to : download data in a blocking way (to be started in a background thread) but also progressively process the data as it is being received (as the

_kCFStreamErrorCodeKey=-2102 only with wifi of some ISPs

五迷三道 提交于 2019-11-29 03:37:35
I use below code to send a file to the server: NSString *urlString = [NSString stringWithFormat:@"%@%@",[LIUtility sharedUtility].uploadConnectionURL,BR_SERVER_UPLOAD_ADDRESS_FILE]; self.request =[[NSMutableURLRequest alloc] init]; [self.request setURL:[NSURL URLWithString:urlString]]; [self.request setHTTPMethod:@"POST"]; PKMultipartInputStream *body = [[PKMultipartInputStream alloc] init]; NSString *requestString =[self getRequestStringForRange:range andExtension:fileName]; NSData *requestData = [requestString dataUsingEncoding:NSUTF8StringEncoding]; NSString *jsonLengthString = [NSString

how to unit test a NSURLConnection Delegate?

Deadly 提交于 2019-11-29 02:55:05
问题 How can I unit test my NSURLConnection delegate? I made a ConnectionDelegate class which conforms to different protocols to serve data from the web to different ViewControllers. Before I get too far I want to start writing my unit tests. But I don't know how to test them as a unit without the internet connection. I would like also what I should do to treat the asynchronous callbacks. 回答1: This is similar to Jon's response, couldn't fit it into a comment, though. The first step is to make sure