Forum Xamarin.iOS

How to implement Share Extension to Xamarin forms - iOS project?

pelinalpppelinalpp Member ✭✭✭
edited February 6 in Xamarin.iOS

Hi,

I am trying to implement share extension to my xamarin forms app. And I followed these:
https://docs.microsoft.com/tr-tr/xamarin/ios/platform/extensions
https://docs.microsoft.com/en-us/samples/xamarin/ios-samples/ios8-share/
https://github.com/xamarin/ios-samples/tree/master/ios8/Share

And git repo above works when I run it. But I need to implement this for my xamarin forms project.
So I did this steps:
1) I right clicked to my xamarin forms solution. After I select add, new project. And I created "Share Extension (iOS)" project. (I choosed .Net Framework 4.7.2)
2) A Share extension project is created with ShareViewController. I didn't do any change this.
3) I opened info.plist of new created ShareExtension project. And I paid attention bundle identifier. For example my xamarin project's bundle identifier is "com.xamarin.test" and my share extension project's bundle identifier is "com.xamarin.test.share-extension"
4) I selected MinimumOSVersion 10.0 of my main project and my share extension.
5) In my project,NSExtension is following:

> <key>NSExtension</key>
> <dict>
>   <key>NSExtensionAttributes</key>
>   <dict>
>       <key>NSExtensionActivationRule</key>
>       <dict>
>           <key>NSExtensionActivationSupportsFileWithMaxCount</key>
>           <integer>1</integer>
>           <key>NSExtensionActivationSupportsImageWithMaxCount</key>
>           <integer>1</integer>
>           <key>NSExtensionActivationSupportsMovieWithMaxCount</key>
>           <integer>1</integer>
>           <key>NSExtensionActivationSupportsText</key>
>           <false/>
>           <key>NSExtensionActivationSupportsWebURLWithMaxCount</key>
>           <integer>1</integer>
>       </dict>
>   </dict>
>   <key>NSExtensionMainStoryboard</key>
>   <string>MainInterface</string>
>   <key>NSExtensionPointIdentifier</key>
>   <string>com.apple.share-services</string>
> </dict>
> 

6) After I cleaned whole solution and rebuilded, I added to reference shared extension project's dll to my xamarin ios project. After that I run the project. (on iphone 7 ios 12.0 simulator)

When I open photos and I click share for a photo, I expect to see my app on share menu. But it doesn't work. I guess I missed a step but what is this, I don't know. Somebody help me please.

Best Answer

  • pelinalpppelinalpp ✭✭✭
    Accepted Answer

    Finally I found my wrong. I always tried to add the extension again. But when I do this:"right click the xamarin ios project --> Add a reference --> Choose Project", extension already there. I thought very wrong.
    And again thank you.

Answers

  • LandLuLandLu Member, Xamarin Team Xamurai

    I created a new solution with a new share extension project. I only modified the BundleIdentifier of the extension project to make it match with the container project.
    Then it could successfully be displayed on the activity view window after deploying on my physical device(iOS 13.3). Have you tried to test it on a real device?
    Moreover, delete the former application first before reinstalling it.
    I attached my sample here. It's a very simple clear project without too much modification.

  • pelinalpppelinalpp Member ✭✭✭
    edited February 7

    Thank you lots of. Your project works when I run on simulator or real devices. But I try to implement this to my xamarin forms project, it doesn't work. Does share extension work only on xamarin.ios(native)?
    I wonder, do I do wrong while I was adding share project to ios project? I am adding a example project and video about what do I do.
    https://drive.google.com/open?id=1_cGKFy9lrZtvz418z5eg3FvwdLWTwy60
    And do I need to do any process on the apple developer side? Because I saw this link: https://medium.com/@timefrancesco/develop-and-deploy-ios8-extensions-with-xamarin-walkthrough-1b059a03e861
    He said "Create an App Group and provisioning Profiles" etc. I also did these steps. But it doesn't run.
    Sorry I asked lots of ask. But I'm stuck here.

  • pelinalpppelinalpp Member ✭✭✭
    Accepted Answer

    Finally I found my wrong. I always tried to add the extension again. But when I do this:"right click the xamarin ios project --> Add a reference --> Choose Project", extension already there. I thought very wrong.
    And again thank you.

Sign In or Register to comment.