首页 > 解决方案 > 在跨平台 xamarin 项目中编写特定于平台的代码

问题描述

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

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

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

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

标签: c#xamarinxamarin.androidxamarin.ioscross-platform

解决方案


欢迎来到堆栈溢出。

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

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


推荐阅读