mirror of
https://github.com/bitwarden/android.git
synced 2024-10-31 15:15:34 +03:00
fix attachments selection on ios
This commit is contained in:
parent
d7130d9b67
commit
14f3f99218
2 changed files with 53 additions and 23 deletions
|
@ -45,8 +45,11 @@ namespace Bit.App.Pages
|
||||||
protected override void OnDisappearing()
|
protected override void OnDisappearing()
|
||||||
{
|
{
|
||||||
base.OnDisappearing();
|
base.OnDisappearing();
|
||||||
|
if(Device.RuntimePlatform != Device.iOS)
|
||||||
|
{
|
||||||
_broadcasterService.Unsubscribe(nameof(AttachmentsPage));
|
_broadcasterService.Unsubscribe(nameof(AttachmentsPage));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private async void Save_Clicked(object sender, EventArgs e)
|
private async void Save_Clicked(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
|
|
|
@ -161,8 +161,15 @@ namespace Bit.iOS.Services
|
||||||
});
|
});
|
||||||
picker.DidPickDocumentPicker += (sender, e) =>
|
picker.DidPickDocumentPicker += (sender, e) =>
|
||||||
{
|
{
|
||||||
controller.PresentViewController(e.DocumentPicker, true, null);
|
if(SystemMajorVersion() < 11)
|
||||||
|
{
|
||||||
e.DocumentPicker.DidPickDocument += DocumentPicker_DidPickDocument;
|
e.DocumentPicker.DidPickDocument += DocumentPicker_DidPickDocument;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
e.DocumentPicker.Delegate = new PickerDelegate(this);
|
||||||
|
}
|
||||||
|
controller.PresentViewController(e.DocumentPicker, true, null);
|
||||||
};
|
};
|
||||||
var root = UIApplication.SharedApplication.KeyWindow.RootViewController;
|
var root = UIApplication.SharedApplication.KeyWindow.RootViewController;
|
||||||
if(picker.PopoverPresentationController != null && root != null)
|
if(picker.PopoverPresentationController != null && root != null)
|
||||||
|
@ -374,27 +381,7 @@ namespace Bit.iOS.Services
|
||||||
|
|
||||||
private void DocumentPicker_DidPickDocument(object sender, UIDocumentPickedEventArgs e)
|
private void DocumentPicker_DidPickDocument(object sender, UIDocumentPickedEventArgs e)
|
||||||
{
|
{
|
||||||
e.Url.StartAccessingSecurityScopedResource();
|
PickedDocument(e.Url);
|
||||||
var doc = new UIDocument(e.Url);
|
|
||||||
var fileName = doc.LocalizedName;
|
|
||||||
if(string.IsNullOrWhiteSpace(fileName))
|
|
||||||
{
|
|
||||||
var path = doc.FileUrl?.ToString();
|
|
||||||
if(path != null)
|
|
||||||
{
|
|
||||||
path = WebUtility.UrlDecode(path);
|
|
||||||
var split = path.LastIndexOf('/');
|
|
||||||
fileName = path.Substring(split + 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
var fileCoordinator = new NSFileCoordinator();
|
|
||||||
fileCoordinator.CoordinateRead(e.Url, NSFileCoordinatorReadingOptions.WithoutChanges,
|
|
||||||
out NSError error, (url) =>
|
|
||||||
{
|
|
||||||
var data = NSData.FromUrl(url).ToArray();
|
|
||||||
SelectFileResult(data, fileName ?? "unknown_file_name");
|
|
||||||
});
|
|
||||||
e.Url.StopAccessingSecurityScopedResource();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SelectFileResult(byte[] data, string fileName)
|
private void SelectFileResult(byte[] data, string fileName)
|
||||||
|
@ -444,5 +431,45 @@ namespace Bit.iOS.Services
|
||||||
var documents = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
|
var documents = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
|
||||||
return Path.Combine(documents, "..", "tmp");
|
return Path.Combine(documents, "..", "tmp");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void PickedDocument(NSUrl url)
|
||||||
|
{
|
||||||
|
url.StartAccessingSecurityScopedResource();
|
||||||
|
var doc = new UIDocument(url);
|
||||||
|
var fileName = doc.LocalizedName;
|
||||||
|
if(string.IsNullOrWhiteSpace(fileName))
|
||||||
|
{
|
||||||
|
var path = doc.FileUrl?.ToString();
|
||||||
|
if(path != null)
|
||||||
|
{
|
||||||
|
path = WebUtility.UrlDecode(path);
|
||||||
|
var split = path.LastIndexOf('/');
|
||||||
|
fileName = path.Substring(split + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var fileCoordinator = new NSFileCoordinator();
|
||||||
|
fileCoordinator.CoordinateRead(url, NSFileCoordinatorReadingOptions.WithoutChanges,
|
||||||
|
out NSError error, (u) =>
|
||||||
|
{
|
||||||
|
var data = NSData.FromUrl(u).ToArray();
|
||||||
|
SelectFileResult(data, fileName ?? "unknown_file_name");
|
||||||
|
});
|
||||||
|
url.StopAccessingSecurityScopedResource();
|
||||||
|
}
|
||||||
|
|
||||||
|
public class PickerDelegate : UIDocumentPickerDelegate
|
||||||
|
{
|
||||||
|
private readonly DeviceActionService _deviceActionService;
|
||||||
|
|
||||||
|
public PickerDelegate(DeviceActionService deviceActionService)
|
||||||
|
{
|
||||||
|
_deviceActionService = deviceActionService;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void DidPickDocument(UIDocumentPickerViewController controller, NSUrl url)
|
||||||
|
{
|
||||||
|
_deviceActionService.PickedDocument(url);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue