Microsoft Intune App SDK Xamarin 元件Microsoft Intune App SDK Xamarin Component


您可能想要先閱讀 Intune App SDK 快速入門文章,其中說明如何在每個支援的平台上進行整合準備。You may wish to first read the Get Started with Intune App SDK article, which explains how to prepare for integration on each supported platform.


Intune App SDK Xamarin 元件 (英文) 能在使用 Xamarin 建置的 iOS 和 Android 應用程式中啟用 Intune 應用程式保護原則The Intune App SDK Xamarin component enables Intune app protection policy in iOS and Android apps built with Xamarin. 元件可讓開發人員輕鬆將 Intune 應用程式內資料保護功能建置到以 Xamarin 為基礎的應用程式。The component allows developers to easily build in Intune app protection features into their Xamarin-based app.


Xamarin 的 Intune SDK 支援目前可供預覽。Support for the Intune SDK for Xamarin is currently available in preview.

Microsoft Intune App SDK Xamarin Component 可讓您將 Intune 應用程式保護原則 (也稱為 APP 或 MAM 原則) 併入使用 Xamarin 所開發的應用程式。The Microsoft Intune App SDK Xamarin Component lets you incorporate Intune app protection policies (also known as APP or MAM policies) into your apps developed with Xamarin. 啟用 MAM 的應用程式是與 Intune App SDK 整合的應用程式,A MAM-enabled application is one that is integrated with the Intune App SDK. IT 系統管理員可在 Intune 主動管理應用程式時,將應用程式保護原則部署至行動應用程式。IT administrators can deploy app protection policies to your mobile app when Intune actively manages the app.

支援的項目What's supported?

開發人員電腦Developer machines

  • macOSmacOS

行動應用程式平台Mobile app platforms

  • AndroidAndroid
  • iOSiOS

Intune 行動應用程式管理案例Intune Mobile Application Management scenarios

  • Intune MDM 已註冊的裝置Intune MDM-enrolled devices
  • 協力廠商 EMM 已註冊的裝置Third-party EMM-enrolled devices
  • 未受管理的裝置 (未使用任何 MDM 註冊)Unmanaged devices (not enrolled with any MDM)

使用 Intune App SDK Xamarin Component 建置的 Xamarin 應用程式,現在可以在 Intune 行動裝置管理 (MDM) 註冊裝置和未註冊裝置上,接收 Intune 應用程式保護原則。Xamarin apps built with the Intune App SDK Xamarin Component can now receive Intune app protection policies on both Intune mobile device management (MDM) enrolled devices and unenrolled devices.


  • [僅限 Android] 最新的 Microsoft Intune 公司入口網站應用程式必須安裝在裝置上。[Android only] The latest Microsoft Intune Company Portal app must be installed on the device.

開始使用Get started

  1. 這裡下載 Xamarin-component.exe 並將它解壓縮。Download Xamarin-component.exe from here and extract it.

  2. 閱讀 Microsoft Intune MAM Xamarin 元件的授權條款Read the license terms for the Microsoft Intune MAM Xamarin Component.

  3. GitHubXamarin 下載 Intune App SDK Xamarin 元件資料夾並將它解壓縮。Download the Intune App SDK Xamarin Component folder from GitHub or Xamarin and extract it. 從步驟 1 和步驟 3 下載的兩個檔案應該在相同的目錄層級中。Both files downloaded from step 1 and step 3 should be in the same directory level.

  4. 以系統管理員身分在命令列執行 Xamarin.Component.exe install <.xam> fileIn the command line as an administrator, run Xamarin.Component.exe install <.xam> file.

  5. 在 Visual Studio 中,以滑鼠右鍵按一下先前所建立 Xamarin 專案中的 [元件]。In Visual Studio, right-click components in your previously created Xamarin project.

  6. 選取 [編輯元件] 並在本機將您下載的 Intune App SDK 元件新增到您的電腦。Select Edit Components and add the Intune App SDK component you’ve downloaded locally to your computer.

在 iOS 行動應用程式中啟用 Intune 應用程式保護原則Enabling Intune app protection polices in your iOS mobile app

  1. 請遵循將 Intune App SDK 整合至 iOS 行動應用程式所需的一般步驟。Follow the general steps required for integrating the Intune App SDK into an iOS mobile app. 您可以從 Intune App SDK for iOS 開發人員指南之整合指示的步驟 3 開始。You can begin with step 3 of the integration instructions from the Intune App SDK for iOS Developer Guide. 重要:在 Visual Studio 中針對應用程式啟用金鑰鏈共用的方式與 Xcode 有些許不同。Important: Enabling keychain sharing for an app is slightly different in Visual Studio from Xcode. 開啟應用程式的 Entitlements plist,並確保 [啟用金鑰鏈] 選項已啟用,且已將適當的金鑰鏈共用群組新增至該區段。Open the app's Entitlements plist and make sure the "Enable Keychain" option is enabled and the appropriate keychain sharing groups are added in that section. 接著,確保 Entitlements plist 已針對所有適當的設定/平台組合,指定於專案 [iOS 套件組合簽署] 選項的 [自訂權利] 欄位中。Then, ensure the Entitlements plist is specified in the "Custom Entitlements" field of the project's "iOS Bundle Signing" options for all the appropriate Configuration/Platform combinations.
  2. 在新增元件且正確設定應用程式之後,您的應用程式便可以開始使用 Intune SDK 的 API。Once the component is added and the app is properly configured, your app can begin using the Intune SDK's APIs. 若要這麼做,您必須包含下列命名空間:To do so, you must include the following namespace:

    using Microsoft.Intune.MAM;
  3. 若要開始接收應用程式保護原則,您的應用程式必須註冊至 Intune MAM 服務。To begin receiving app protection policies, your app must enroll in the Intune MAM service. 如果您的應用程式已使用 Azure Active Directory Authentication Library (ADAL) 來驗證使用者,應用程式應該在成功驗證之後,將使用者的 UPN 提供給 IntuneMAMEnrollmentManager 的 registerAndEnrollAccount 方法:If your app already uses the Azure Active Directory Authentication Library (ADAL) to authenticate users, your app should provide the user's UPN to the IntuneMAMEnrollmentManager's registerAndEnrollAccount method after it has successfully authenticated:

    IntuneMAMEnrollmentManager.Instance.RegisterAndEnrollAccount(string identity);

    重要:請務必以您應用程式的 ADAL 設定覆寫 Intune App SDK 的預設 ADAL 設定。Important: Be sure to override the Intune App SDK's default ADAL settings with those of your app. 若要這麼做,您可以依 Intune App SDK for iOS 開發人員指南中所述的方式透過應用程式 Info.plist 中的 IntuneMAMSettings 目錄,或是使用 IntuneMAMPolicyManager 執行個體的 AAD 覆寫屬性來完成。You can do so via the IntuneMAMSettings dictionary in the app's Info.plist, as mentioned in the Intune App SDK for iOS Developer Guide, or you can use the AAD override properties of the IntuneMAMPolicyManager instance. Info.plist 方法是針對 ADAL 設定為靜態之應用程式的建議選項,而覆寫屬性則是針對會於執行階段決定那些值之應用程式的建議選項。The Info.plist approach is recommended for applications whose ADAL settings are static while the override properties are recommended for applications that determine those values at runtime.

    如果您的應用程式不使用 ADAL,且想要由 Intune SDK 負責處理驗證,您的應用程式便應呼叫 IntuneMAMEnrollmentManager 的 loginAndEnrollAccount 方法:If your app does not use ADAL, and you'd like the Intune SDK to handle authentication, your app should call the IntuneMAMEnrollmentManager's loginAndEnrollAccount method:

     IntuneMAMEnrollmentManager.Instance.LoginAndEnrollAccount([NullAllowed] string identity);

在 Android 行動應用程式中啟用應用程式保護原則Enabling app protection policies in your Android mobile app

若為未使用 UI 架構且以 Xamarin 為基礎的 Android 應用程式,您必須閱讀並遵循 Intune App SDK for Android 開發人員指南For Xamarin-based Android apps not using a UI framework, you need to read and follow the Intune App SDK for Android Developer Guide. 針對您以 Xamarin 為基礎的 Android 應用程式,您必須根據指南中包含的資料表,將類別、方法和活動取代為其 MAM 對等項目。For your Xamarin-based Android app, you need to replace class, methods, and activities with their MAM equivalent based on the table included in the guide. 如果您的應用程式未定義 類別,則需要建立一個,並確定繼承自 MAMApplicationIf your app doesn’t define an class, you need to create one and ensure that you inherit from MAMApplication.

針對 Xamarin 表單和其他 UI 架構,我們提供了稱為 MAM.Remapper 的工具。For Xamarin Forms and other UI frameworks, we have provided a tool called MAM.Remapper. 此工具會為您完成類別取代。The tool accomplishes the class replacement for you. 不過,您必須執行下列步驟︰However, you need to do the following steps:

  1. 新增對 Microsoft.Intune.MAM.Remapper.Tasks NuGet 套件 版或更新版本的參考。Add a reference to the Microsoft.Intune.MAM.Remapper.Tasks NuGet package version or greater.

  2. 將下行新增至您的 Android csproj:Add the following line to your Android csproj:

    Project="$(NugetPack)\\Microsoft.Intune.MAM.Remapper.Tasks.0.1.X.X\\build\\MonoAndroid10\\Microsoft.Intune.MAM.Remapper.targets" />
  3. 將新增之 remapping-config.json 檔案的建置動作設為 RemappingConfigFileSet the build action of the added remapping-config.json file to RemappingConfigFile. 包含的 remapping-config.json 僅適用於 Xamarin.Forms。The included remapping-config.json only works with Xamarin.Forms. 若為其他 UI 架構,請參閱 Remapper NuGet 套件所包含的讀我檔案。For other UI frameworks, refer to the Readme included with the Remapper NuGet package.

接下來的步驟Next steps

您已完成將元件建置成應用程式的基本步驟。You have completed the basic steps of building the component into your app. 現在您可以依照 Xamarin Android 範例應用程式中的步驟。Now you can follow the steps included in the Xamarin Android sample app. 我們提供了兩個範例,一個用於 Xamarin.Forms,另一個適用於 Android。We have provided two samples, one for Xamarin.Forms and another for Android.