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.

概觀Overview

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.

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.

必要條件Prerequisites

  • [僅限 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,您需要在 AppDelegate.cs 類別中呼叫任何 API。In order to initialize the Intune App SDK, you need to make a call for any API in the AppDelegate.cs class. 例如:For example:

    public override bool FinishedLaunching (UIApplication application, NSDictionary launchOptions)
    {
          Console.WriteLine ("Is Managed: {0}", IntuneMAMPolicyManager.Instance.PrimaryUser != null);
          return true;
    }
    
  2. 既然已新增並初始化元件,您可以依照將 App SDK 建置成 iOS 行動應用程式所需的一般步驟。Now that the component is added and initialized, you can follow the general steps required for building the App SDK into an iOS mobile app. 您可以在 Intune App SDK for iOS 開發人員指南中找到啟用原生 iOS 應用程式的完整文件。You can find the full documentation for enabling native iOS apps in the Intune App SDK for iOS Developer Guide.

  3. 重要︰有 Xamarin 為基礎的 iOS 應用程式特有的一些修改。Important: There are several modifications specific to Xamarin-based iOS apps. 例如,啟用 Keychain 群組時,您必須新增下列內容,以納入我們在元件中包含的 Xamarin 範例應用程式。For instance, when enabling keychain groups, you need to add the following to include the Xamarin sample app we included in the component. 以下是在金鑰鏈存取群組中必須要有的群組範例︰Below is an example of the groups you would need to have in your Keychain Access groups:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    <plist version="1.0">
          <dict>
                <key>keychain-access-groups</key>
                <array>
                      <string>$(AppIdentifierPrefix)com.xamarin.microsoftintunesample</string>
                      <string>$(AppIdentifierPrefix)com.xamarin.microsoftintunesample.intunemam</string>
                      <string>$(AppIdentifierPrefix)com.microsoft.intune.mam</string>
                      <string>$(AppIdentifierPrefix)com.microsoft.adalcache</string>
                </array>
          </dict>
    </plist>
    

您已完成將元件建置成以 Xamarin 為基礎的 iOS 應用程式所需的步驟。You have completed the steps necessary to build the component into your Xamarin-based iOS app. 如果您使用 Xcode 來建置您的專案,可以使用 Intune App SDK Settings.bundleIf you are utilizing Xcode for building your project, you can use the Intune App SDK Settings.bundle. 這可讓您在建置專案來測試和偵錯時,開啟或關閉 Intune 原則設定。This allows you to toggle Intune policy settings on and off as you build your project to test and debug. 若要利用此套組,請依照 Intune App SDK for iOS 開發人員指南中的步驟,並閱讀關於在 Xcode 中偵錯的小節。To take advantage of this bundle, follow the steps in the Intune App SDK for iOS Developer Guide and read the section on debugging in Xcode.

在 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. 如果您的應用程式未定義 android.app.Application 類別,則需要建立一個,並確定繼承自 MAMApplicationIf your app doesn’t define an android.app.Application 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 套件 0.1.0.0 版或更新版本的參考。Add a reference to the Microsoft.Intune.MAM.Remapper.Tasks NuGet package version 0.1.0.0 or greater.

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

    <Import
    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.