2016-05-27 05:22:38 +03:00
|
|
|
using System;
|
|
|
|
using CoreGraphics;
|
2016-05-07 08:54:44 +03:00
|
|
|
using Foundation;
|
2016-05-27 05:22:38 +03:00
|
|
|
using MobileCoreServices;
|
2016-05-07 08:54:44 +03:00
|
|
|
using UIKit;
|
|
|
|
|
|
|
|
namespace Bit.iOS.Extension
|
|
|
|
{
|
|
|
|
public partial class ActionViewController : UIViewController
|
|
|
|
{
|
2016-05-27 05:22:38 +03:00
|
|
|
public ActionViewController() : base("ActionViewController", null)
|
2016-05-07 08:54:44 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-05-27 05:22:38 +03:00
|
|
|
public string HtmlContent { get; set; }
|
|
|
|
public Uri BaseUri { get; set; }
|
|
|
|
public Uri Url { get; set; }
|
2016-05-07 08:54:44 +03:00
|
|
|
|
|
|
|
public override void DidReceiveMemoryWarning()
|
|
|
|
{
|
|
|
|
base.DidReceiveMemoryWarning();
|
|
|
|
}
|
|
|
|
|
2016-05-27 05:22:38 +03:00
|
|
|
public override void LoadView()
|
|
|
|
{
|
|
|
|
View = new UIView(new CGRect(x: 0.0, y: 0, width: 320.0, height: 200.0));
|
|
|
|
var button = new UIButton(new CGRect(x: 10.0, y: 50.0, width: 200.0, height: 30.0));
|
|
|
|
button.SetTitle("Done", UIControlState.Normal);
|
|
|
|
button.TouchUpInside += Button_TouchUpInside;
|
|
|
|
View.AddSubview(button);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void Button_TouchUpInside(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
var itemData = new NSDictionary(
|
2016-05-28 07:59:36 +03:00
|
|
|
"username", "me@example.com",
|
|
|
|
"password", "mypassword",
|
|
|
|
"autoSubmit", true);
|
2016-05-27 05:22:38 +03:00
|
|
|
|
|
|
|
var resultsProvider = new NSItemProvider(
|
2016-05-28 07:59:36 +03:00
|
|
|
new NSDictionary(NSJavaScriptExtension.FinalizeArgumentKey, itemData), UTType.PropertyList);
|
2016-05-27 05:22:38 +03:00
|
|
|
|
2016-05-28 07:59:36 +03:00
|
|
|
var resultsItem = new NSExtensionItem { Attachments = new NSItemProvider[] { resultsProvider } };
|
2016-05-27 05:22:38 +03:00
|
|
|
var returningItems = new NSExtensionItem[] { resultsItem };
|
2016-05-28 07:59:36 +03:00
|
|
|
|
2016-05-27 05:22:38 +03:00
|
|
|
ExtensionContext.CompleteRequest(returningItems, null);
|
|
|
|
}
|
|
|
|
|
2016-05-07 08:54:44 +03:00
|
|
|
public override void ViewDidLoad()
|
|
|
|
{
|
|
|
|
base.ViewDidLoad();
|
|
|
|
|
|
|
|
foreach(var item in ExtensionContext.InputItems)
|
|
|
|
{
|
|
|
|
foreach(var itemProvider in item.Attachments)
|
|
|
|
{
|
2016-05-25 07:09:11 +03:00
|
|
|
if(!itemProvider.HasItemConformingTo(UTType.PropertyList))
|
2016-05-07 08:54:44 +03:00
|
|
|
{
|
2016-05-25 07:09:11 +03:00
|
|
|
continue;
|
2016-05-07 08:54:44 +03:00
|
|
|
}
|
2016-05-25 07:09:11 +03:00
|
|
|
|
|
|
|
itemProvider.LoadItem(UTType.PropertyList, null, (NSObject list, NSError error) =>
|
|
|
|
{
|
|
|
|
if(list == null)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var dict = list as NSDictionary;
|
|
|
|
var result = dict[NSJavaScriptExtension.PreprocessingResultsKey];
|
|
|
|
if(result == null)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-05-27 05:22:38 +03:00
|
|
|
HtmlContent = result.ValueForKey(new NSString("htmlContent")) as NSString;
|
|
|
|
BaseUri = new Uri(result.ValueForKey(new NSString("baseUri")) as NSString);
|
|
|
|
Url = new Uri(result.ValueForKey(new NSString("url")) as NSString);
|
2016-05-25 07:09:11 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
break;
|
2016-05-07 08:54:44 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2016-05-27 05:22:38 +03:00
|
|
|
}
|