Monotouch.Dialog ImageLoader - monotouch.dialog

Monotouch 5.2.11 Eval Version (testing it out)
On the simulator whatever images I am trying to load I get this error:
Error fetching picture for [url to image] to....
Problem with [url to image] System.Net.WebException: The request timed out
at System.Net.HttpWebRequest.EndGetResponse (IAsyncResult asyncResult) [0x00046] in /Developer/MonoTouch/Source/mono/mcs/class/System/System.Net/HttpWebRequest.cs:824
at System.Net.HttpWebRequest.GetResponse () [0x0000e] in /Developer/MonoTouch/Source/mono/mcs/class/System/System.Net/HttpWebRequest.cs:836
at MonoTouch.Dialog.Utilities.ImageLoader.Download (System.Uri uri, System.String target) [0x00038]
The [url to image] works fine, I can actually type in the url on the simulator browser and it loads.. I've downloaded the Monotouch.Dialog project and increased the request timeout to 100000 which doesn't seem to do much.
Any suggestions?

I was getting this error when I had a nested dialog based on some json responses. There were about 1000 photos and the imageloader was trying to load them all. I thought it was only called when clicked which was not the case. It seems the downloads were flooding the system with too many requests.
I fixed this by reusing 1 UIViewController to display the last nested level (it had the photo on it).

Related

How to handle errors inside didFailProvisionalNavigation properly?

I have a viewController with a wkwebview inside it that acts as a custom webBrowser inside my app. I am getting the following errors when i try to access certain urls:
Sometimes a url will throw -1008 (resource unavailable) error when i try to open it the first time (after launching the app), successive tries work fine though.
While navigation a website, clicking on a link leads to -999 (operation could not be completed) error, even though i click on a link inside the website only after it had loaded. So don't know how the operation did not complete. Moreover, the link clicked on website loads just fine.
I couldn't find much on these errors, is there a way to handle all of the possible ones robustly.
A similar question was asked before but didn't get a response: How do I properly implement didFailProvisionalNavigation with WKWebView?

Continue uploading NSData even connection lost/user clicked on home NSUrlConnection

I need to upload via HTTP Post NSData which is UIImage or NSUrl of a video file via the iPhone app which I develop for ios6
I need to support the following cases:
The user clicked on home - to continue uploading in background
The connection is lost - to continue uploading when there is a new internet connection even if the user left the app by clicking on the home button)
The user quit the app (clicked on x) and it was in the middle of uploading, next time that he would open the app, it will continue
In case 2 and 3:
It will continue from the same location that it was in the NSData (not start from the beginning of the file)
It will send in the new call a variable index={index} (where index is the amount of times that it continues starting from 0
I know how to use NSURLConnection as an async connection. But how to support the above 3 cases?
For this to work you need 2 things:
A record, stored persistently, of how much data has been uploaded to the server.
A server which accepts the Content-Range header and can handle storing partial uploads and completing them later. (or a server with an API to handle the same function).
If you have both of these things then you can perform the task using NSURLConnection and its delegate methods, NSUserDefaults (or similar) to store the progress information and subdataWithRange: (or perhaps NSFileHandle) to get only the data which needs to be uploaded.
Look at using connection:didSendBodyData:totalBytesWritten:totalBytesExpectedToWrite: to get updates of what data has been sent. Store that number (if not all of the data has been sent) into user defaults. Once all the data has been sent, remove the number from user defaults.
Use subdataWithRange: by creating a range from the stored number to the (total length of data - the number).

Error while uploading image to flickr in iphone(Xcode 4.2)

In my app, I want to share an image to flickr.
I used the libraries provided by flickr. After authorization I call the following method
[self.flickrRequest uploadImageStream:[NSInputStream inputStreamWithData:JPEGData] suggestedFilename:#"Pic 2 Print" MIMEType:#"image/jpeg" arguments:[NSDictionary dictionaryWithObjectsAndKeys:#"0", #"is_public", nil]];
but I get this error
kUploadImageStep Error Domain=org.lukhnos.ObjectiveFlickr
Code=2147418115 "The operation couldn’t be completed.
(org.lukhnos.ObjectiveFlickr error 2147418115.)
If anyone knows then plz help me.
Thanks in advance.
For me the solution was with the default user agent the lib is using. It seems like Flickr is blocking connections from iOS. When I put a different user agent, HTTPRequest.userAgent = #"hehe"; I got it working.

Use UIWebView Private API?

I want to make a Browser like Safari with UIWebView,
which can show the loading progress of the web page.
And I saw an app "Downloads Lite - Downloader & Download Manager" selling in app store
(http://itunes.apple.com/app/id349275540?&mt=8) that can do this.
It also can customize User Agent of request,
even get "content type" of Response Header to decide whether it's needed to be downloaded.
But it seems that it's impossible to make it happen with the public APIs of UIWebView,
so I'm wondering how he did that.
Could you give me some tips about this?
There is no need for private API to do things like this.
You take a progress indicator for example. By using asynchronous NSURLConnection you can get the size of the expected size of the content you want to download :
-(void)connection:(NSURLConnection*)connection didReceiveResponse:(NSURLResponse*)response
{
[response expectedContentLength];
}
Then you simply compare with the amount of data you downloaded so far.
Customizing User Agents can be done with CFNetwork framework.
have a look at this app/blog: icab.de
General approach is to make subclass of NSProtocol and catch all http/https request, that gives you all you want.

download in one click issue

i want to download file from web server and for that I need
1. send request for file path to web service method
2. receive this path on iphone side
3. now convert this path into NSURL
4. and finally send the request to web server for file download
right now i am doing all above but user have to
1. GetURL button and then
2. Download button
I want all this in one button click.
I tried for this too but problem is:
DownlloadButtonClick
{
[self getURL];
[self DownloadFile];
}
getURL{
soapmsg
NSURL
NSURLReuest
...
..
..
}
//after this i was expecting that connection should be done and data(filepath) will be received,
but this not happen
after getURL() method its back to above and call DownloadFile() and then app will crash...
app is crash this is accepted as i know its depend on getURL() method..
now my problem is where should i place getURL() method and DownloadFile() method so i can execute both on one click
thank you in advance
If I've understood your hard to decipher question correctly...
Your problem seems to be that you want to do an asynchronous action - getURL - and then when that has completed, another action. In your DownlloadButtonClick method, you want to think about only calling getURL (and not DownloadFile yet). In whatever code you have for handling the result of getURL (i.e. the URL has been fetched), you can then kick off your DownloadFile action.