select file for document picker

This commit is contained in:
Kyle Spearrin 2017-07-15 01:09:06 -04:00
parent dac4ffcb98
commit d0b616ba24
4 changed files with 75 additions and 0 deletions

View file

@ -122,5 +122,10 @@ namespace Bit.Android.Services
return false;
}
}
public byte[] SelectFile()
{
return null;
}
}
}

View file

@ -5,6 +5,7 @@
void CopyToClipboard(string text);
bool OpenFile(byte[] fileData, string id, string fileName);
bool CanOpenFile(string fileName);
byte[] SelectFile();
void ClearCache();
}
}

View file

@ -10,5 +10,9 @@
<array>
<string>$(AppIdentifierPrefix)com.8bit.bitwarden</string>
</array>
<key>com.apple.developer.ubiquity-container-identifiers</key>
<array>
<string>$(TeamIdentifierPrefix)com.8bit.bitwarden</string>
</array>
</dict>
</plist>

View file

@ -3,6 +3,7 @@ using Bit.App.Abstractions;
using UIKit;
using Foundation;
using System.IO;
using MobileCoreServices;
namespace Bit.iOS.Services
{
@ -83,5 +84,69 @@ namespace Bit.iOS.Services
var tmp = Path.Combine(documents, "..", "tmp");
return tmp;
}
public byte[] SelectFile()
{
var controller = GetVisibleViewController();
var allowedUTIs = new string[]
{
UTType.AliasFile,
UTType.AliasRecord,
UTType.AppleICNS,
UTType.Image,
UTType.Movie,
UTType.GIF,
UTType.Video,
UTType.Folder,
UTType.ApplicationFile,
UTType.JPEG,
UTType.PNG,
UTType.BMP,
UTType.Spreadsheet
};
var picker = new UIDocumentMenuViewController(allowedUTIs, UIDocumentPickerMode.Open);
picker.AddOption("Camera", null, UIDocumentMenuOrder.First, () =>
{
var imagePicker = new UIImagePickerController { SourceType = UIImagePickerControllerSourceType.Camera };
imagePicker.FinishedPickingMedia += (sender, ev) =>
{
//var filepath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "tmp.png");
//var image = (UIImage)ev.Info.ObjectForKey(new NSString("UIImagePickerControllerOriginalImage"));
//DismissViewController(true, null)
};
imagePicker.Canceled += (sender, ev2) =>
{
//DismissViewController(true, null)
};
controller.PresentModalViewController(imagePicker, true);
});
picker.AddOption("Photo Library", null, UIDocumentMenuOrder.First, () =>
{
var imagePicker = new UIImagePickerController { SourceType = UIImagePickerControllerSourceType.PhotoLibrary };
imagePicker.FinishedPickingMedia += (sender, ev) =>
{
//var filepath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "tmp.png");
//var image = (UIImage)ev.Info.ObjectForKey(new NSString("UIImagePickerControllerOriginalImage"));
//DismissViewController(true, null)
};
imagePicker.Canceled += (sender, ev2) =>
{
//DismissViewController(true, null)
};
controller.PresentModalViewController(imagePicker, true);
});
controller.PresentViewController(picker, true, null);
return null;
}
}
}