question

RoniCakar-9263 avatar image
0 Votes"
RoniCakar-9263 asked JessieZhang-2116 edited

Xamarin.iOS: Share Extension doesn't load url

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.

dotnet-xamarin
· 5
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I did a test,but we couldn't reproduce this problem.Could you please post a basic demo to github or onedriver so that we can test on our side?

0 Votes 0 ·

Hey @JessieZhang-2116,
I have posted a project. :)

0 Votes 0 ·

Sorry for late response . I will check your demo and come back asap. Thank you for your patience.

0 Votes 0 ·

Hello @JessieZhang-2116 ,

sorry for my late response. Here is a link to a basic example with the same issue: https://github.com/12oni/ShareTestApp.git

Thx a lot.

0 Votes 0 ·

We did a test based on your demo. But we couldn't trigger method DidSelectPost .
Our step is:
1. opened a website in browser and share it to this app;
2. after that ,we opened the app, but we couldn't trigger method DidSelectPost;

Is there something wrong with our steps?

0 Votes 0 ·

0 Answers