在跨平台 xamarin 项目中编写特定于平台的代码

Write platform specific code in crossplatform xamarin project

我尝试在我的跨平台 Xamarin 项目中使用 Xamarin.Android 命名空间。当我现在构建 .iOS 项目时,我收到通知,这个命名空间显然不存在 iOS。

我如何编写特定于平台的代码,我在哪里使用特定于平台的库?

我已经查看了 Microsoft 文档,但没有找到任何可以解决我的问题的信息。

PS:这是我对 Stack Overflow 的第一次贡献,如需更多详细信息,请随时询问。

欢迎来到堆栈溢出。

https://docs.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/dependency-service/introduction

以上是 link DependencyService 文档。 DependencyService 允许您作为开发人员从您的 Xamarin.Forms 共享代码中调用特定于平台的代码。