How to implement Share Extension to Xamarin.Forms - iOS project?

廉价感情. 提交于 2020-04-17 21:38:24

问题


I am trying to implement a 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.


回答1:


Your problem is here:

After I cleaned whole solution and rebuilded, I added to reference shared extension project's dll to my xamarin ios project.

In the document, when it says about Container app project requirements:

It must maintain a reference to the Extension project.

You should right click the xamarin ios project --> Add a reference --> Choose the shared extension project. What you are doing is a opposite way.

So remove the wrong reference and add the new reference, clean and rebuild your solution, run again.

Update:




回答2:


Can Deployment Targets be different?I added Share extension it worked directly. Info.plist also looks correct. Is Deployment Target iOS 12+?

Edit: First answer is another question's answer. Let's think as if it didn't never exist :)



来源:https://stackoverflow.com/questions/60093390/how-to-implement-share-extension-to-xamarin-forms-ios-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!