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.

您會發現,您可以啟用 SDK 功能,而不需要變更您的應用程式行為。You will find that you can enable SDK features without changing your app’s behavior. 一旦將元件建置到您的 iOS 或 Android 行動應用程式,IT 系統管理員便可以透過支援各種資料保護功能的 Microsoft Intune 行動應用程式管理 (MAM) 來部署原則。Once you've built the component into your iOS or Android mobile app, the IT admin will be able to deploy policy via Microsoft Intune Mobile Application Management (MAM) supporting a variety of data protection features.

支援的項目What's supported?

開發人員電腦Developer machines

  • WindowsWindows

行動應用程式平台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 元件建置的 Xamarin 應用程式,現在可以在 Intune 行動裝置管理 (MDM) 註冊裝置和未註冊裝置上,接收 Intune 行動應用程式管理 (MAM) 原則。Xamarin apps built with the Intune App SDK Xamarin Component can now receive Intune mobile application management (MAM) 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 always 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 MAMEnabling Intune MAM in your iOS mobile app

  1. 為了初始化 Intune App SDK,您需要能夠在 AppDelegate.cs 類別中呼叫任何 API。In order to initialize the Intune App SDK, you will 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. 比方說,當啟用金鑰鏈群組時,您必須新增下列內容,以包含我們在元件中包含的 Xamarin 範例應用程式。For instance, when enabling keychain groups, you'll 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 will allow 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 行動應用程式中啟用 MAMEnabling MAM in your Android mobile app

若為未使用 UI 架構且以 Xamarin 為基礎的 Android 應用程式,您必須閱讀並遵循 [Intune App SDK for Android 開發人員指南]。For Xamarin-based Android apps not using a UI framework, you will need to read and follow the [Intune App SDK for Android Developer Guide]. 針對您以 Xamarin 為基礎的 Android 應用程式,您必須根據指南中包含的資料表,將類別、方法和活動取代為其 MAM 對等項目。For your Xamarin-based Android app, you will 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 will 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 will accomplish the class replacement for you. 不過,您必須執行下列步驟︰However, you will need to do the following steps:

  1. 新增對 Microsoft.Intune.MAM.Remapper.Tasks nuget 套件 0.1.0.0 版或更新版本的參考。Add a reference to theMicrosoft.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.

測試應用程式Test your app

您已完成將元件建置成應用程式的基本步驟。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.

若要提交意見反應,請前往 Intune Feedback