Initial experience of Xamarin.ios development

Source: Internet
Author: User


Xamarin is a cross-platform development framework that supports the development of iOS, Android, Windows phone, and Mac applications in C #, a framework that is implemented in mono.


Mono is an open-source project based on the. NET Framework that includes the C # language compiler, the CLR runtime, and a set of class libraries that can run on Windows, Linux, Unix, Mac OS, and Solaris.
For. NET programmer, Xamarin is a cross-platform development artifact for Android, IOS, and Mac that can be developed not only in familiar C #, but also in Visual Studio as an IDE. This article is a xamarin.ios version of the development of the first experience.

I. Installing the development environment

For developing IOS apps with Xamarin, the preparation is two-step: (1) Install the Xamarin.ios SDK under Windows and VS, (2) Install Xamarin.iOS.Build host and Xcode under Mac. Because Xamarin iOS for Visual Studio allows iOS apps to be written under Windows, it can only be deployed and debugged on a remote MAC host or iOS device.
1.Windows
Under Windows systems, first make sure that Xamarin's Full Installation Wizard is downloaded from Xamarin's official website, and that the Installation Wizard provides iOS and Android suite installation, which you can choose.

I have been stuck here when I installed Xamarin using the Setup Wizard:


The process of acquiring an optional kit for Android and iOS has been linked to failure, initially thinking it was a system version issue (I'm Win8.1 64 bit), and after communicating with some experts, I discovered that these resources were dropped by the wall ... FQ self-addressed. I also contacted the customer service to receive the following reply:

There is a couple possible causes of the issue, but it looks like a manual uninstall/reinstall would get everything Worki ng properly.
1) Press the Windows button + R to open the Run window.
2) Type appwiz.cpl to open the ADD & Remove Programs window.
3) Find Xamarin & Xamarin Studio (Optional) and uninstall them.
4) Once They ' re uninstalled, or if you ' re unable to find them; Please follow the installation steps below.

Download and install the packages shown below in the order listed:

1. JDK 1.6:http://download.xamarin.com/installer/monoforandroid/jdk-6u39-windows-i586.exe
2. Android Sdk:http://dl.google.com/android/installer_r22-windows.exe
3. gtk#: Http://download.xamarin.com/GTKforWindows/Windows/gtk-sharp-2.12.25.msi
4. Xamarin Studio:http://download.xamarin.com/studio/windows/xamarinstudio-5.0.0.878-0.msi
5. Xamarin for Windows (includes xamarin.ios for Visual Studio and xamarin.android): Http://download.xamarin.com/Xamarinf Orvisualstudio/windows/xamarin.visualstudio_setup-3.0.54.0.msi

I Hope this helps!
-kent Green
Developer Support

Ignoring Android SDK/JDK and Xamarin studio,gtk# is an encapsulation of the cross-platform graphical user interface library GTK +, which Windows users can ignore and install with mono on a non-Windows platform gtk# Similar to Windows Forms and WPF. So you just need to install one xamarin for Windows alone. The latest version of Xamarin for Windows supports VS2012 and VS2013, please poke here

After the installation is complete, open the VS2013, the new Project window can see more iOS and Android directories, indicating that the installation was successful:

2.Mac
Xamarin.ios supports Mac OS 10.7 and later.

Download Xcode 5 to iOS Dev center first

Next you can choose to install the full Xamarin, or just install the Xamarin.ios Build Host

Two. Configuring the Deployment Debugging Environment

Because there is no iOS emulator under Windows, you need to link to a networked remote Mac host. In addition to the previous section where Xcode and Xamarin.ios are installed, the network needs to be configured.
On your Mac, in Network preferences, enable and set up the proxy for the current network, and shut down the firewall in security and privacy in System preferences.

Open Xamarin.ios Build Host:

Click Pairing to automatically generate a PIN code that is used in the VS settings under Windows:

Back to Windows, open VS2013, the first will automatically let us account login, the use of the account that you need to create on the Xamarin website account, I use the trial version of the license, have the ability to pay to use the official version of it, of course, the free version can be used, There is only a size limit when releasing the program.

On the Menu Tools->options->xamarin->ios Settings tab, click Find Mac Build Host:



Enter the pin that you generated under your Mac to complete the pairing so that Windows can connect to the MAC host remotely and debug the iOS program remotely under Windows.

Three. Create an iOS app

Open VS2013, create a new project, select the Ios->iphone->blank app template, named Helloopenxlive, you can see the project structure as follows:

You can see the Monotouch in the reference node, which is the Xamarin.ios SDK, which implements the basic functionality of IOS with. Net.

Main.cs for the entry of the program, start an inherited from Uiapplicationdelegate named Appdelegate, in the Appdelegate to complete the program start and initialization work.

AppDelegate.cs, in the Finishedlaunching method, we can add the desired image (View) through the rootviewcontroller of the form, which is somewhat similar to the MVC pattern. We right-click Project--Add Item, add an iphone View Controller, named Hellouiviewcontroller:

Open HelloUIViewController.cs:

1 publicoverride voidViewDidLoad()
2 {
3     View = newUniversalView();
4
5     base.ViewDidLoad();
6 }

First, a common view is added, that is, the background view, you can modify the default background color arbitrarily, in the Initialize method of the Universalview class

1 voidInitialize()
2 {
3     BackgroundColor = UIColor.White;
4 }

So far the picture is still blank, we go back to the Hellouiviewcontroller class Viewdidload method, add a label, display a paragraph of text:

01 publicUILabel CustomLabel;
02
03 publicoverride voidViewDidLoad()
04 {
05     View = newUniversalView();
06
07     base.ViewDidLoad();
08
09     // Perform any additional setup after loading the view
10     CustomLabel = newUILabel(newRectangleF(0, 100, 300, 30))
11     {
12         Text = "Hello, OpenXLive!",
13         TextAlignment = UITextAlignment.Center,
14     };
15     View.Add(CustomLabel);
16 }

In the toolbar, set debug options, select Debug, Iphonesimulator, and specify an emulator type (such as iphone Retina (4-inch) IOS 7.1), and press F5 to start debugging

Under the Mac host, you can see that an iOS simulator is started and initialized, our program is deployed after the simulator is started, and then we can debug the breakpoint:

Do not spit groove why there is no iphone shell, this is because the use of the Mac host is older, no retina screen, the resolution cannot keep up, so the fruit shell is not shown, if the resolution is enough to automatically display it.

Next I'll show you how to migrate a. NET third-party library to iOS via Xamarin (iOS calls openxlive via Xamarin)

Summarize

This article describes the mono-based Xamarin framework, which supports the development of IOS, Android, Windows phone, and Mac apps using C #, describes the installation and configuration methods of Xamarin.ios, and describes how to use Xamarin.ios The SDK is developed under Windows and is debugged on a Mac remote host.

Initial experience of Xamarin.ios development

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.