Skip to content

Instantly share code, notes, and snippets.

@chrisntr
Created December 13, 2011 18:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrisntr/d4c87703d3453f086aa2 to your computer and use it in GitHub Desktop.
Save chrisntr/d4c87703d3453f086aa2 to your computer and use it in GitHub Desktop.
using MonoTouch.UIKit;
using System.Drawing;
using System;
using MonoTouch.Foundation;
using System.Net;
namespace DownloadingProj
{
public partial class DownloadingProjViewController : UIViewController
{
public DownloadingProjViewController () : base ("DownloadingProjViewController", null)
{
}
public override void DidReceiveMemoryWarning ()
{
// Releases the view if it doesn't have a superview.
base.DidReceiveMemoryWarning ();
// Release any cached data, images, etc that aren't in use.
}
UIButton button, button2;
WebClient webClient;
public override void ViewDidLoad ()
{
base.ViewDidLoad ();
webClient = new WebClient();
button = UIButton.FromType(UIButtonType.RoundedRect);
button.Frame = new RectangleF(0f, 20f, 280f, 40f);
button.SetTitle("Download file", UIControlState.Normal);
button.TouchUpInside += (sender, e) => {
webClient.DownloadDataAsync(new Uri("http://dl.dropbox.com/u/90453/Big12mbfile.xap"), "bigfile.xap");
webClient.DownloadProgressChanged += delegate(object sender2, DownloadProgressChangedEventArgs e2) {
InvokeOnMainThread(() => {
button.SetTitle(e2.BytesReceived.ToString(), UIControlState.Normal);
});
};
webClient.DownloadDataCompleted += delegate(object sender3, DownloadDataCompletedEventArgs e3) {
InvokeOnMainThread(() => {
button.SetTitle("Completed: Cancelled = " + e3.Cancelled, UIControlState.Normal);
});
};
//webClient.CancelAsync();
};
button2 = UIButton.FromType(UIButtonType.RoundedRect);
button2.Frame = new RectangleF(0f, 60f, 280f, 40f);
button2.TouchUpInside += (sender4, e4) => {
webClient.CancelAsync();
};
button2.SetTitle("Cancel download", UIControlState.Normal);
View.AddSubview(button);
View.AddSubview(button2);
//any additional setup after loading the view, typically from a nib.
}
public override void ViewDidUnload ()
{
base.ViewDidUnload ();
// Release any retained subviews of the main view.
// e.g. myOutlet = null;
}
public override bool ShouldAutorotateToInterfaceOrientation (UIInterfaceOrientation toInterfaceOrientation)
{
// Return true for supported orientations
return (toInterfaceOrientation != UIInterfaceOrientation.PortraitUpsideDown);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment