public ImageViewController()
{
Title = "AirPic Demo";
// on iOS 8.x we delegate the AirPlay feature to our Action extension
bool ios8 = UIDevice.CurrentDevice.CheckSystemVersion (8,0);
// the action extension will do the browsing for airplay capable devices
AirPlayBrowser.Enabled = !ios8;
var bounds = UIScreen.MainScreen.Bounds;
image_view = new UIImageView (bounds);
image_view.Image = UIImage.FromFile ("687px-Leontopithecus_rosalia_-_Copenhagen_Zoo_-_DSC09082.JPG");
image_view.Image.Scale (bounds.Size);
Add (image_view);
UIBarButtonItem action = null;
action = new UIBarButtonItem (UIBarButtonSystemItem.Action, delegate {
if (image_view.Image == null)
return;
// UIActivity is only for iOS6+ but that should not limit us :-)
if (UIDevice.CurrentDevice.CheckSystemVersion (6,0)) {
var activities = AirPlayBrowser.Enabled ? UIAirPlayActivity.GetCurrentActivities () : null;
var a = new UIActivityViewController (new [] { image_view.Image }, activities);
if (AppDelegate.RunningOnIPad) {
popup = new UIPopoverController (a);
popup.PresentFromBarButtonItem (action, UIPopoverArrowDirection.Up, true);
} else {
PresentViewController (a, true, null);
}
} else {
var devices = AirPlayBrowser.GetDeviceNames ();
var a = new UIActionSheet (null, null, "Cancel", null, devices);
a.Clicked += (sender, e) => {
nint index = e.ButtonIndex;
// ignore Cancel button
if (index < devices.Length) {
var device = AirPlayBrowser.GetDevice (devices [index]);
if (device != null) // they can disappear anytime
device.SendTo (image_view.Image, null);
}
};
a.ShowFrom (NavigationItem.RightBarButtonItem, true);
}
});
NavigationItem.RightBarButtonItem = action;
}