ASIHTTPRequest Error, Code 2, on actual iPad - xcode

I have a program that asynchronously downloads 4 files into the Documents folder of an ipad, and this works perfectly on the simulator, but when I use it on an actual ipad it gives me this error:
Error Domain=ASIHTTPRequestErrorDomain Code=2 "The request timed out" UserInfo=0x1c0810 {NSLocalizedDescription=The request timed out}
Is there any way to fix this, or extend the time until time out?

The reason why you are getting better results in the simulator is probably because the simulator uses the built in network card and your Mac's network card is likely stronger than the one in the iPad.
You can use the following code to change the timeout interval. This code will set the timeout to twenty seconds:
[request setTimeOutSeconds:20]
According to the ASIHTTPRequest "How to Use" page, you can tell ASIHTTPRequest to try again N times, like so:
[request setNumberOfTimesToRetryOnTimeout:2];
EDIT:
Although it's 2016 and ASIHTTPRequest is long since deprecated, there's another useful bit of information to help diagnose networking issues on iOS devices. Try using the Network Link Conditioner. It ships with iOS and can be downloaded on macOS.
This article (link) from NSHipster has some great information on getting set up.

Cause of this problem may be the following. When we send a httprequest and don't received response from server but at this time you send another httprequest again and with second request response is received before first request.

Related

What does "ERR_HTTP2_PING_FAILED" mean in Chrome error code?

That error message logged to the chrome console from a long-pending request after around 15 minutes.
It looks client-side error because server processing still worked.
I did not find any article related to this error message.
can any buddy let me know how to solve this issue?
According to the chromium source I think it means that a spdy ping timed out.
...
{net::ERR_EMPTY_RESPONSE, "http.response.empty"},
{net::ERR_HTTP2_PING_FAILED, "spdy.ping_failed"},
{net::ERR_HTTP2_PROTOCOL_ERROR, "spdy.protocol"},
...
Source https://chromium.googlesource.com/chromium/src/+/lkgr/components/domain_reliability/util.cc#48
Chrome sends such pings before and after a request.
Source https://groups.google.com/d/msg/spdy-dev/HFjAbFRd-N0/p-Edt-lneGsJ

Chromecast sample sender application CastHelloText-chrome ends with error when trying to get session

I have problem with launching Google-Cast application similar to sample CastHelloText-chrome. I slightly modified example code for my specific purposes. The goal for creating this application is to send and show image data directly in Chromecast device.
Particularly the difference between official sample and my code is in message format and its content, sent by sender application. Sender application took png image coded by base64 and send through message bus with custom namespace. Receiver application get this message and use this as data source for html object <img>.
Error appears when I do this steps:
Reload sender page, checking console if any device found.
Send the form by just pushing enter on input box (text is ignored).
Now a popup from Chromecast extension shows. Next there are two scenarios:
3a) I confirm casting to device by choosing one from the list, then I get this error message in console:
onError: {"code":"channel_error","description":"Error: Timeout","details":null}
3b) I just click somewhere else, I get this error:
onError: {"code":"cancel","description":"User closed popup menu","details":null}
Both of errors are caused by calling function chrome.cast.requestSession in chromehellotext.html at line 161, but what's really wrong I don't know.
When I step sender script I realize that function sessionListener is never called. I know that something go wrong when code try to call chrome.cast.requestSession, where described error raises. So I need help if I missed about right way to use Google-Cast API or If this problem has something to do with networking issues.
Receiver application is registered on Google Cast SDK Developer Console and I'm testing on registered device with some serial number. I'm using Google Chrome in version 42.0.2300.2 canary (64-bit) and Chrome version 40.0.2214.111 (current stable I suppose). For testing I also tried to turn off Windows Firewall entirely but with no luck.
Edit:
There were some syntactic errors that caused error message described above.
It seems like you are trying to use the data/control channel to send an image; please don't do that; that channel is not meant to be used for large data communications; in fact it cannot send anything which approaches or exceeds 64k. If your goal is to send images from your local machine, you would need to run a local web server on your local machine and serve images through the web server.
For and easiest tutorial you can have a look to this tutorial.
It is well explained in this tutorial.
Chromecast Sender application
There is no need to maintain session by yourself.
just add button and enjoy casting
mCastManager.addMediaRouterButton(mediaRoutebtn);
I found a source of my problem. There was something wrong in receiver code - syntactic and runtime errors, so I must admit that my code wasn't functional. Now its working in terms of launching application and getting session.
Unfortunate thing is that the error message generated by Chromecast extension didn't match the actual error - at least it was a bit confusing when I didn't know what's really happening on receiver side without ability to debug the code.

iOS8: NSURLSession: NSURLSessionDataTask 'Client closed connection before receiving entire response'

I use iOS BACKGROUND FETCH n BACKGROUND TRANSFER to update our app.
When we download an MP4 as part of a large download of lots of files the download can stop suddenly and get error:
'Client closed connection before receiving entire response'
http code is still 200.
We have no limit on data due to corporate cellular accounts and have single apps on our iPad so management want us to download a larger amount of data and number of files sometime over 20/30 on a clean install.
They're corporate videos/ pdfs published daily.
I created a NSURLSession
NSURLSession * backgroundSession_ = [NSURLSessionConfiguration backgroundSessionConfigurationWithIdentifier:identifier]
Then for each URL to the mp4 or PDF I create a NSURLSessionDownloadTask from my NSURLSession
NSURLSessionDownloadTask * downloadTask_ = [backgroundSession_ downloadTaskWithURL:url_];
The fire off resume on each download task.
When all return the NSURLSession completes and I tell the user in a notification that the apps has been updated.
I use CHARLES PROXY on my mac to monitor the downloads.
It takes a while as there are many files and also I noticed the movies seem to stream so can be slow.
Usually it checks whats been downloaded and only downloads the latest but if I do a lot of downloads say to a clean install I noticed that quiet often the streams to the mp4 get killed.
They have a 200 code but with message
'Client closed connection before receiving entire response'
Any idea what may cause this because it can stop my NSURLSession from completing so my sync can get in a sort of hung state.
IMAGE: OK DOWNLOAD: MOVIE STREAMS AND SAVED TO DISK: 200: Complete
IMAGE: DOWNLOAD SUDDENLY STOPS:
Any ideas: I use Background Fetch so not sure if the client in the message is iOS8 or my app.
After each downloadtask returns I copy the tmp file to mp4 in documents and call
[session finishTasksAndInvalidate];
if some of these downloadtask fail then I notice the session never finishes and gets stuck.
When I do another fetch I get all these old download task and old sessions.
was asked how I solved this but two years laster.
We also shrunk the movie files as well to speed up downloads.
I also remember the session and the configuration having separate settings. I had set header in one but failed when iOS 8/9 came out as it should have been set in the session not just the config - but may be fixed now as iOS 10 out
//-----------------------------------------------------------------------------------
//some movie streams time out n get
//'http://stackoverflow.com/questions/23428793/nsurlsession-how-to-increase-time-out-for-url-requests'
//'Client closed connection before receiving entire response'
NSLog(#"urlSessionConfigurationBACKGROUND_.timeoutIntervalForRequest:%f", urlSessionConfigurationBACKGROUND_.timeoutIntervalForRequest);
NSLog(#"urlSessionConfigurationBACKGROUND_.timeoutIntervalForResource:%f", urlSessionConfigurationBACKGROUND_.timeoutIntervalForResource);
//was 60
//urlSessionConfigurationBACKGROUND_.timeoutIntervalForRequest = 240.0;
urlSessionConfigurationBACKGROUND_.timeoutIntervalForRequest = 600.0;
// urlSessionConfigurationBACKGROUND_.timeoutIntervalForResource = 60.0;
You can ask your server mate to change the content-type to video/mpeg4 or you can change your request type from GET to POST

Apple Maps requests are returning Error Forbidden 403

I started working in an app which needs to display maps at some point. I wanted to go with apple's built in support for this(aka Mapkit), but haven't succeeded so far.
I started playing with mapkit using this example. The MKMapView is always displaying a blank grid, which is not the expected result.
Then I checked in the simulator Debug >> Open System Log... and I found the following in the responses for the map tiles requests:
Jan 27 21:04:33 ppp-177var5.pppi.enet.cu geod[1234] <Warning>: Error downloading resource: Error Domain=GEOErrorDomain Code=-601 "The operation couldn’t be completed. (GEOErrorDomain error -601.)" UserInfo=0x2d5ea10 {NSErrorFailingURLStringKey=http://gspa21.ls.apple.com/stylesheet/default-522.styleproto?sid=00&tk=9697a89581dee74b03f5fa7dac0dbf37&mapkey=1390864469_017ead13c5015c535f5af0b037507566, HTTP Status Code=403}
Also, I checked for the simulator connectivity by navigating with Safari, and DID work!.
Obviously, apple servers are returning forbidden for the maps http requests.
Here is a snapshot of debugging with Charles's (web debugger):
For more info, I am running OS X 10.9.1(Mavericks) on a mac mini. Also, I think this is not a problem of country restriction because I connected through a VPN located in the UK and didn't work.
I tested the Maps app provided by OS X and I got the same forbidden error.
My questions are:
Why is this happening?
What are the parameters sid,tk and mapkey in the query string of the map tiles requests.
Please, avoid suggesting switching to Mapbox framework since this is not what I am looking for.

MPMoviePlayerController - catching network errors when loading a movie

Is there a way of catching exceptions (particularly for network errors
/ no connection available) when using a MPMoviePlayerController?
I am particularly concerned that once an instance of the player is initialised with initWithURL: you have no way of knowing whether the movie load has failed for some reason.
I have reviewed the available documentation and realise I can get a
notification for loadState changes through
moviePlayerLoadStateChanged:(NSNotification*)notification.
Problem is the loadState constants available don't cater for error handling:
MPMovieLoadStateUnknown
MPMovieLoadStatePlayable
MPMovieLoadStatePlaythroughOK
MPMovieLoadStateStalled
(in case you are wondering, MPMovieLoadStateStalled this doesn't get called during network errors for some reason?)
There's a deprecated MPMoviePlayerContentPreloadDidFinishNotification that provides a userInfo dictionary with an "error" key but nothing for iOS 3.2 and above.
Any help would be very much appreciated.
In the end I got this sorted by subscribing to MPMoviePlayerPlaybackDidFinishNotification and watching for MPMovieFinishReasonPlaybackError.
More details here https://developer.apple.com/library/ios/documentation/MediaPlayer/Reference/MPMoviePlayerController_Class/Reference/Reference.html#//apple_ref/doc/uid/TP40006953-CH3-SW17

Resources