Hello :)
I'm creating an iOS App with Xamarin Forms on VS for Mac.
I add a share extension simply to get the URL of an Website. Everything is working fine except the loadItem-part. Here is my code:
public override void DidSelectPost()
{
// This is called after the user selects Post. Do the upload of contentText and/or NSExtensionContext attachments.
string description = "";
string url = "";
WriteToDebugFile("Lets begin");
foreach (var extensionItem in ExtensionContext.InputItems)
{
WriteToDebugFile("First forEach");
if (extensionItem.Attachments != null)
{
WriteToDebugFile("if not null");
foreach (var attachment in extensionItem.Attachments)
{
WriteToDebugFile("Forech attachment");
if (attachment.HasItemConformingTo(UTType.URL))
{
WriteToDebugFile("if URL type");
WriteToDebugFile(attachment.ToString());
attachment.LoadItem(UTType.URL, null, (data, error) =>
{
WriteToDebugFile(error.ToString());
NSUrl nsUrl = (NSUrl)data;
url = nsUrl.ToString();
WriteToDebugFile($"URL - {url}");
//Save off the url and description here
//alert.AddAction(UIAlertAction.Create("Posten", UIAlertActionStyle.Default, action => WriteInFile()));
});
}
}
}
if (!string.IsNullOrWhiteSpace(extensionItem.AttributedContentText.Value))
{
description = extensionItem.AttributedContentText.Value;
WriteToDebugFile($"URL description - {description}");
}
}
// Inform the host that we're done, so it un-blocks its UI. Note: Alternatively you could call super's -didSelectPost, which will similarly complete the extension context.
ExtensionContext.CompleteRequest(new NSExtensionItem[0], null);
}
My Info.plist:
<key>NSExtension</key>
<dict>
<key>NSExtensionAttributes</key>
<dict>
<key>NSExtensionActivationRule</key>
<dict>
<key>NSExtensionActivationSupportsWebURLWithMaxCount</key>
<integer>1</integer>
<key>NSExtensionActivationSupportsWebPageWithMaxCount</key>
<integer>1</integer>
</dict>
</dict>
<key>NSExtensionMainStoryboard</key>
<string>MainInterface</string>
<key>NSExtensionPointIdentifier</key>
<string>com.apple.share-services</string>
</dict>
My Debug File:
5/12/2021 11:41:57 PM - Lets begin
5/12/2021 11:41:57 PM - First forEach
5/12/2021 11:41:57 PM - if not null
5/12/2021 11:41:57 PM - Forech attachment
5/12/2021 11:41:57 PM - if URL type
5/12/2021 11:41:57 PM - <NSItemProvider: 0x60000035e300> {types = (
"public.url"
)}
5/12/2021 11:41:57 PM - URL description - Dance - Wikipedia
Thanks in advance.