I'm working on Xamarin Forms Application with dependency service to open the file ( Doc/image) in the UIDocumentInteraction Controller. Newly we implemented Share Extension to share the files to our app and the same is reflecting inside the app share option too. But we need to hide our app from share option inside the app. Kindly suggest how to hide/disable share for the current app (own app) inside the app share option.
I tried to use the WillBeginSendingToApplication event but its not triggering to share extension app's ( As our current app too) and tried with DidDismissOptionsMenu event but here we're not getting which app is clicked on the OptionsMenu list. So finding hard to control the sharing to current app. Kindly help or share your feedback to proceed.
Thanks in Advance.
public class DocumentSharingService : IDocumentSharingService
{
private UIDocumentInteractionController docInteractionController;
public bool ShareDocument(string documentPath)
{
var documentNSURL = NSUrl.CreateFileUrl(new[] {documentPath});
docInteractionController = UIDocumentInteractionController.FromUrl(documentNSURL);
var element = Current.MainPage.FindVisualElement(e => RoleManager.GetRole(e) == "ShareDocument");
var clickedButton = Platform.GetRenderer(element).NativeView;
var viewController = UIApplication.SharedApplication.KeyWindow?.RootViewController;
docInteractionController.Delegate = new ShareUIDocumentInteractionControllerDelegateClass(viewController);
docInteractionController.DidDismissOptionsMenu += DocInteractionController_DidDismissOptionsMenu;
docInteractionController.WillBeginSendingToApplication += DocInteractionController_WillBeginSendingToApplication;
var isDisplayed = docInteractionController.PresentOptionsMenu(clickedButton.Frame, clickedButton.Superview, false);
return isDisplayed;
}
private void DocInteractionController_DidDismissOptionsMenu(object sender, EventArgs e)
{
Console.WriteLine("DocInteractionController_DidDismissOptionsMenu");
}
private void DocInteractionController_WillBeginSendingToApplication(object sender, UIDocumentSendingToApplicationEventArgs e)
{
Console.WriteLine("DocInteractionController_WillBeginSendingToApplication");
}
}
public class ShareUIDocumentInteractionControllerDelegateClass : UIDocumentInteractionControllerDelegate
{
private UIViewController mViewController;
public ShareUIDocumentInteractionControllerDelegateClass(UIViewController viewController)
{
mViewController = viewController;
//mFile = file;
}
public override UIViewController ViewControllerForPreview(UIDocumentInteractionController controller)
{
return mViewController;
}
public override UIView ViewForPreview(UIDocumentInteractionController controller)
{
return mViewController.View;
}
public override void DidEndPreview(UIDocumentInteractionController controller)
{
Console.WriteLine("WillEndPreview");
}
public void WillBeginSendingToApplication(UIDocumentInteractionController controller, string application)
{
Console.WriteLine("WillEndPreview");
}
}