Есть ли правильный способ добиться этого в .NET iOS с расширением общего доступа или без него?
Что я уже пробовал:
- Создал проект расширения общего доступа через XCode.
Он создает все необходимые папки/файлы в нашем проекте. - Класс Принцип преобразован в UIViewcontroller вместо SLCompose.
- Переопределен требуемый метод для загрузки изображения с помощью NSContext.
- Создайте новые профили и группа приложений.

< /p>
Код: Выделить всё
void LoadImage (NSExtensionContext extensionContext = null) {
var image = new NSExtensionItem [0];
NSExtensionItem inputItem;
if (extensionContext == null) {
inputItem = ExtensionContext.InputItems [0];
}
else {
inputItem = extensionContext.InputItems [0];
}
var outputItem = inputItem.Copy () as NSExtensionItem;
var itemProvider = outputItem.Attachments [0];
string imageTypeIdentifier = "public.image";
string pdfTypeIdentifier = "com.adobe.pdf";
var test = itemProvider.GetRegisteredTypeIdentifiers (NSItemProviderFileOptions.OpenInPlace);
if (!(itemProvider.HasItemConformingTo (imageTypeIdentifier)) || itemProvider.HasItemConformingTo (pdfTypeIdentifier)) {
OpenUrl (NSUrl.FromString ($"myapp://itemtypeimagedoesnotexists)"));
return;
}
itemProvider.LoadItem (imageTypeIdentifier, null, (item, loadError) => {
if (item != null && loadError == null) {
InvokeOnMainThread (() => {
OpenUrl (NSUrl.FromString ($"myapp://{item.ToString ()}"));
if (item is UIImage) {
SaveImageToAppGroup (item as UIImage, "shared_image_url.txt");
}
});
}
else {
InvokeOnMainThread (() => {
OpenUrl (NSUrl.FromString ($"myapp://itemisnullorhasloaderror"));
});
}
});
itemProvider.LoadItem (pdfTypeIdentifier, null, (item, loadError) => {
if (item != null && loadError == null) {
InvokeOnMainThread (() => {
OpenUrl (NSUrl.FromString ($"myapp://{item.ToString ()}"));
if (item is NSData) {
SavePdfToAppGroup (item as NSData, "shared_image_pdf.txt");
}
});
}
else {
InvokeOnMainThread (() => {
OpenUrl (NSUrl.FromString ($"myapp://itemisnullorhasloaderror"));
});
}
});
}
public void SaveImageToAppGroup (UIImage image, string fileName) {
var appGroupPath = NSFileManager.DefaultManager.GetContainerUrl (APP_GROUP_IDENTIFIER);
var directoryPath = appGroupPath.Path;
if (!NSFileManager.DefaultManager.FileExists (directoryPath)) {
NSError createDirError = null;
NSFileManager.DefaultManager.CreateDirectory (appGroupPath, true, null, out createDirError);
}
NSData imgData = image.AsJPEG ();
var filePath = Path.Combine (directoryPath, fileName);
NSError saveError = null;
imgData.Save (filePath, NSDataWritingOptions.Atomic, out saveError);
}
Есть какие-нибудь сведения?
Подробнее здесь: https://stackoverflow.com/questions/793 ... ormerly-xa