Xamarin iOS 應用程式基本概念Xamarin.iOS application fundamentals

本節提供開發人員在開發 Xamarin iOS (先前稱為 MonoTouch)應用程式時需要注意的一些常見工作或概念的指南。This section provides a guide on some of the more common things tasks or concepts that developers need to be aware of when developing Xamarin.iOS (formerly MonoTouch) applications.


本檔說明各種 Api 和工具,可用來協助建立可供多個使用者使用的應用程式。This document describes various APIs and tools that can be used to help build applications that are accessible to as many users as possible.

應用程式傳輸安全性App Transport Security

本文將介紹應用程式傳輸安全性在 iOS 9 應用程式上強制執行的安全性變更,以及這對您的 Xamarin iOS 專案所代表的意義。它會涵蓋 ATS 設定選項,並將涵蓋如何退出宣告 ATS (如有需要)。This article will introduce the security changes that App Transport Security enforces on an iOS 9 app and what this means for your Xamarin.iOS projects, it will cover the ATS configuration options and it will cover how to opt-out of ATS, if required. 因為預設會啟用 ATS,所以任何不安全的網際網路連線都會在 iOS 9 應用程式中引發例外狀況(除非您已明確允許)。Because ATS is enabled by default, any non-secure internet connections will raise an exception in iOS 9 apps (unless you've explicitly allowed it).


背景處理或背景處理是在另一個應用程式于前景執行時,讓應用程式在背景中執行工作的進程。Background processing or backgrounding is the process of letting applications perform tasks in the background while another application is running in the foreground. 本指南可做為 iOS 中的背景處理簡介。This guide serves as an introduction to background processing in iOS.

在程式碼中建立 iOS 應用程式Creating iOS applications in code

本文將探討如何使用 Visual Studio 和 Visual Studio for Mac,完全以程式碼建立 iOS 應用程式。This article examines how to create iOS applications entirely in code using Visual Studio and Visual Studio for Mac. 它會示範如何從空的專案範本開始,藉由從 UIKit 建立 views 的階層,在控制器中建立應用程式畫面。It shows how to start from an empty project template to build an application screen in a controller by creating a hierarchy of views from UIKit. 然後,它會討論如何建立可在控制器中載入的自訂視圖。Then, it discusses how to create custom views that can be loaded in a controller.

例外狀況封送處理Exception marshaling

描述如何在原生和 managed 框架之間封送處理目標 C 和 managed 例外狀況。Describes how Objective-C and managed exceptions are marshaled between native and managed frames.

事件、通訊協定和委派Events, protocols, and delegates

本文提供用來接收回呼以及使用資料填入使用者介面控制項的主要 iOS 技術。This article presents the key iOS technologies used to receive callbacks and to populate user interface controls with data. 這些技術包括事件、通訊協定和委派;本文說明其中的每個專案,以及如何使用每個C#。These technologies are events, protocols, and delegates; this article explains what each of these is and how each is used from C#. 它會示範 Xamarin 如何使用 iOS 控制項來公開熟悉的 .NET 事件,以及 Xamarin 如何提供對目標-C 概念(例如通訊協定和委派)的支援(如不應該與C#委派混淆的目標-c 的委派)。It demonstrates how Xamarin.iOS uses iOS controls to expose familiar .NET events, as well as how Xamarin.iOS provides support for Objective-C concepts such as protocols and delegates (Objective-C delegates should not be confused with C# delegates). 本文也會提供範例,說明如何使用通訊協定作為目標-C 委派和非委派案例的基礎。This article also provides examples that show how protocols are used both as the basis for Objective-C delegates and in non-delegate scenarios.

使用檔案系統Working with the file system

在 ios 中,您可以使用相同的 System.IO 類別來處理您在任何 .NET 應用程式中使用的檔案和目錄。Xamarin.iOS can use the same System.IO classes to work with files and directories in iOS that you would use in any .NET application. 不過,儘管常見的類別和方法,iOS 仍會對可建立或存取的檔案進行一些限制,同時也提供特定目錄的特殊功能。However, despite the familiar classes and methods, iOS implements some restrictions on the files that can be created or accessed and also provides special features for certain directories. 本文概述這些限制和功能,並示範檔案存取在 Xamarin iOS 應用程式中的運作方式。This article outlines these restrictions and features, and demonstrates how file access works in a Xamarin.iOS application.

使用影像Working with images

本文將探討如何在 Xamarin 中使用影像,這兩個應用程式都支援影像(例如圖示、載入影像等)和應用程式內的影像(例如套用至控制項的影像)。This article examines how to use images in Xamarin.iOS, both application support images (such as icons, loading images, etc.) and images within applications (such as images applied to controls). 其中也涵蓋如何使用 Visual Studio for Mac 來併入影像,以及如何從程式碼與影像互動。It also covers how to use Visual Studio for Mac to incorporate images as well as how to interact with images from code.


本指南涵蓋將編碼新增至支援國際化的 Xamarin iOS 應用程式。This guide covers the addition of encodings to a Xamarin.iOS application to support internationalization.

使用屬性清單Working with property lists

本檔介紹 Visual Studio for Mac 的圖形化和先進的屬性清單(. plist)編輯器,以使用 plist 和 plist。This document introduces Visual Studio for Mac's graphical and advanced property list (.plist) editor for working with Info.plist and Entitlements.plist. 其中說明如何設定適用于 iOS 應用程式的圖示和啟動影像,並示範如何在 Visual Studio for Mac 內指定應用程式功能(權利)。It illustrates setting icons and launch images for iOS application, and demonstrates specifying app capabilities (entitlements) from inside Visual Studio for Mac.

使用安全性和隱私權Working with security and privacy

Apple 在 iOS 10 (及更新版本)中提供了許多安全性和隱私權方面的增強功能,可協助開發人員改善其應用程式的安全性,並確保使用者的隱私權。Apple has made several enhancements to both security and privacy in iOS 10 (and greater) that will help the developer improve the security of their apps and ensure the end user's privacy. 本文將討論如何在 Xamarin iOS 應用程式中執行這些功能。This article will cover implementing these features in a Xamarin.iOS app.


本文討論 Xamarin iOS 應用程式中的執行緒,並稍微談一下 .NET 執行緒集區、回應式應用程式和垃圾收集。This article discusses threading in a Xamarin.iOS application, and talks a bit about the .NET thread pool, responsive applications, and garbage collection.


現今許多裝置上的觸控式螢幕可讓使用者以自然且直覺的方式,快速且有效率地與裝置互動。Touch screens on many of today’s devices allow users to quickly and efficiently interact with devices in a natural and intuitive way. 這種互動並不只限于簡單的觸控式偵測,也可以使用手勢。This interaction is not limited just to simple touch detection – it is possible to use gestures as well. 例如,縮小到縮放手勢是一個很常見的範例,也就是捏合螢幕的一部分,使用者可以放大或縮小兩個手指。本指南會檢查 iOS 中的觸控和手勢。For example, the pinch-to-zoom gesture is a very common example of this – by pinching a part of the screen with two fingers the user can zoom in or out. This guide examines touch and gestures in iOS.

使用使用者預設值Working with user defaults

NSUserDefaults 類別可讓 iOS 應用程式和延伸模組以程式設計方式與全系統的預設系統互動。The NSUserDefaults class provides a way for iOS Apps and Extensions to programmatically interact with the system-wide Default System. 藉由使用預設系統,使用者可以設定應用程式的行為或樣式,以符合其喜好設定(根據應用程式的設計)。By using the Defaults System, the user can configure an app's behavior or styling to meet their preferences (based on the design of the app). 例如,若要呈現度量與英制測量的資料,或選取特定的 UI 主題。For example, to present data in Metric vs Imperial measurements or select a given UI Theme.