I am working on an IOS application. It launches a WebView and loads an HTML page under that using NSURLRequest. Once the initial page is loaded, different html links on that page will be traversed to fetch different information. All works well when HTML links respond within 10 seconds, but http requests are terminated/timeout when the response time is more than 10 seconds. I am not sure, what exactly times out. Is it the NSURLRequest/WebView/ etc. I don't set any timeout value for the initial NSURLRequest. Note that the slow requests(>10 sec response time) works well in a normal web browser, so there is no server side logic that terminates/times out the request.
I have implemented the UIWebViewDelegate in my IOS code and I see the following function called even for the timed out requests:
(void)webViewDidFinishLoad:(UIWebView *)webView
On the server side, the request keep processing and finally finishes successfully but IOS webView is already finished loading the page so does not display the result.
I am trying to figure out any timeout settings related to NSURLRequest/WebView/ etc.
To increase timeout delay to 30 seconds on a NSURLRequest I use following constructor:
NSURLRequest *theRequest = [NSURLRequest requestWithURL:theURL cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:30];
Related
I am doing an application in which I am uploading the images to twitpic. It works fine the first time. But if I try to upload the next image within that minute itself, it shows a 401 error. If I try again after waiting for a minute, it gives a 200 response and works fine. Why is this happening? Can I send images continuously to twit pic without any interruption?
Well the documentation of TwitPic states that there is 500 call limit on the API.
And the 401 will happen only if you do supply the correct Auth header.
My guess is that there is something wrong with the auth header, it might be due to caching.
If you use NSURLConnection nochache paramter:
NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:60];
I have a UIWebView control loading a URL that have AJAX on HTML. My concern is to stop AJAX request on the page. I can stop all further navigation by using delegate method as:
- (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest: (NSURLRequest*)req navigationType:(UIWebViewNavigationType)navigationType {
Or I can use the simple method [webView stopLoading], but non of these able to stop internal AJAX request running on browser.
Please suggest if is there any way where we can stop AJAX
Ajax URLs are not passed to shouldStartLoadWithRequest, only page and iframe loads. To capture any other sort of network traffic you can use NSURLCache which is basically a cache layer between UIWebView and network. It can also capture requests based on some rules you defined and return an error or empty response for it as if that error was in the cache.
Here is a sample to replace some url content:
http://cocoawithlove.com/2010/09/substituting-local-data-for-remote.html
We host a website with some videos, and we're aiming to restrict these videos so only an specific referer can access to them. We were using secdownload, but seems to be a pain with HTTP Live Streaming.
In our iPhone APP, we're trying to customize the HTTP Header fields by setting our custom referer or user-agent and be able to play this videos.
We customize it this way
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:self.UrlString]];
[theRequest setValue: customreferer forHTTPHeaderField:#"Referer"];
If we start a connection (NSConnection) everything is fine, but the problem comes when using with MPMoviePlayerController, because it seems that there is no way to customize its http requests.
You can specify an NSURL in MPMoviePlayerController, but doesn't seem to allow you to edit the request.
Am I missing something? If so, how do we achieve this? We're outputting the log from apache and all the HTTP requests made by the movieplayer have an empty referer.
That is correct. To use a MPMoviePlayerController with a different URL, you should release the original and alloc/initWithContentURL: a new one. You could consider adding a parameter to the URL, or customise the URL in some other way, to identify the referrer.
But I am aware of no way of getting at the NSURLRequest.
I track user activity in my iPhone app by having certain user actions call an almost empty Web page that the app does nothing with. Rather, attached to the URL are some querystring paramaters that tell me who's doing something and what it is (after I analyze the logs, that is).
I don't want launching the URL to slow down the app, so I prefer not to wait at all for any response. So after getting a bunch of device info and user action info and attaching that to a querystring, I call:
NSURLRequest *oRequest = [NSURLRequest requestWithURL: oURL cachePolicy: (etc) timeoutInterval: 2.0];
NSURLConnection *oConnection = [[NSURLConnection alloc] initWithRequest:oRequest delegate: self];
Is this the fastest way to create a Web log entry while hindering my app the least?
You might put your request in the background by wrapping it in a selector and calling -performSelectorInBackground:withObject:. Or do the same within a one-off NSInvocationOperation.
This doesn't speed up the communication between the phone and the server, but it does put the request on a background thread, so that your app's user can keep doing whatever she is doing mostly unimpeded.
Which is the best way to handle request-timeout. I am sending XML request and if I didn't get response in 10 sec I need to stop activity indicator and show alert message.
Which approach is best out of following:
a. NSTimer - To check status of response
b. NSThread - This will run in background to check response
c. Notification class (I never used it)
Thanks
If you use NSMutableURLRequest then you can give time interval in this
for eg.
NSMutableURLRequest *theRequest=[NSMutableURLRequest requestWithURL:[NSURL URLWithString:url] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:10.0];
so no need to use timer or thread