Xamarin. iOS development experience

Source: Internet
Author: User
Tags gtk

Xamarin is a cross-platform development framework that supports C # development of IOS, Android, Windows Phone, and Mac applications. It is implemented by Mono at the underlying layer.

Mono is an open-source project based on the. NET Framework. It contains a C # Language compiler, CLR runtime, and a group of class libraries that can run on Windows, Linux, Unix, Mac OS, and Solaris.

 

For. NET programmers, Xamarin is an artifact for cross-platform development for Android, iOS, and Mac. It can be developed not only with familiar C #, but also with Visual Studio as IDE. This article describes the development experience of Xamarin. iOS.

 

1. Install the development environment

For iOS app development using Xamarin, the preparation is divided into two steps: (1) install Xamarin in Windows. iOS SDK and VS, (2) install Xamarin on Mac. iOS. build Host and XCode. Because Xamarin iOS for Visual Studio allows IOS applications to be written in Windows, it can only be deployed and debugged on a remote Mac host or iOS device.

1. Windows

In Windows, make sure that the complete installation wizard of Xamarin is downloaded from the Xamarin official website. The Installation Wizard will provide installation for IOS and Android.

When I installed Xamarin using the Installation Wizard, I kept stuck here:

The link failed during the process of obtaining the Android and iOS optional suites. At first, it was thought that it was a system version problem (I am Win8.1 64-bit ), after talking with some experts, I found that these resources were damaged... Solve the problem by turning over the wall. I also contacted customer service and got a reply as follows:

There are a couple possible causes of the issue, but it looks like a manual uninstall/reinstall wocould get everything working 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.

Please 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 (des Xamarin. iOS for Visual Studio and Xamarin. Android): http://download.xamarin.com/XamarinforVisualStudio/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 GTK +, a cross-platform graphical user interface library, which can be ignored by Windows users. It will be installed along with Mono, on non-Windows platforms, GTK # is similar to Windows Forms and WPF. Therefore, you only need to install an Xamarin for Windows. The latest version of Xamarin for Windows supports VS2012 and VS2013.

After the installation is complete, open VS2013. In the new project window, the iOS and Android directories are displayed, indicating that the installation is successful:

 

 

2. Mac

Xamarin. iOS supports Mac OS 10.7 and later versions.

First download Xcode 5 from iOS Dev Center

 

Next, you can choose to install the complete Xamarin, or only install Xamarin. iOS Build Host

 

2. Configure the deployment and debugging environment

Because there is no iOS simulator in Windows, you need to connect to a networked remote Mac host. In addition to Xcode and Xamarin. iOS installed in the previous section, you also need to configure the network.

In Mac, enable and set the proxy of the current network in network preference settings, and disable the firewall in System Preference Settings> security and privacy.

 

Open Xamarin. iOS Build Host:

Click pairing to automatically generate a string of PIN codes, which are used in VS settings in Windows:

 

Go back to Windows and open VS2013. First, we will automatically log on to the Account. The account used is the one you need to create when downloading the Xamarin official website. Here I use the Trial License, if you have the ability to pay for the official version, you can also use the free version, but there is a size limit when releasing the program.

On the menu Tools> Options> Xamarin> iOS Settings tab, click Find Mac Build Host:

 

Enter the PIN code generated on the Mac to complete the pairing. In this way, Windows establishes a remote connection with the Mac host and can remotely debug the iOS program on Windows.

 

3. Create an iOS app

Open VS2013, create a project, select iOS-> iPhone-> Blank App template, and name it HelloOpenXLive. The project structure is as follows:

We can see that the monotouch in the referenced node is the Xamarin. iOS SDK, and the basic functions of iOS are implemented using. NET.

Main. cs is the entry of the program. Start an AppDelegate inherited from UIApplicationDelegate to start and initialize the program in AppDelegate.

In AppDelegate. cs, In the FinishedLaunching method, we can add the desired screen (View) through the form RootViewController. This structure is somewhat similar to the MVC mode. Right-click the project and choose add item to add an iPhone View Controller named HelloUIViewController:

Open HelloUIViewController. cs,

public override void ViewDidLoad(){    View = new UniversalView();    base.ViewDidLoad();}

First, a general view, that is, the background view, is added. You can modify the Default background color at will. In the Initialize method of the UniversalView class

void Initialize(){    BackgroundColor = UIColor.White;}

So far, the screen is still blank. We will return to the ViewDidLoad method of the HelloUIViewController class and add a Label to display a text:

public UILabel CustomLabel;public override void ViewDidLoad(){    View = new UniversalView();    base.ViewDidLoad();    // Perform any additional setup after loading the view    CustomLabel = new UILabel(new RectangleF(0, 100, 300, 30))    {        Text = "Hello, OpenXLive!",        TextAlignment = UITextAlignment.Center,    };    View.Add(CustomLabel);}

In the toolbar, set debugging options, select DEBUG and iPhoneSimulator, specify a simulator type (such as iPhone Retina (4-inch) iOS 7.1), and press F5 to start debugging.

On the Mac host, we can see that an iOS simulator is started and initialized. Our program is deployed after the simulator is started. Then we can perform breakpoint debugging:

Do not tell why there is no iPhone shell. This is because the Mac host is old, there is no Retina screen, and the resolution cannot keep up, so the fruit shell is not displayed; if the resolution is enough, it is automatically displayed.

 

Next I will introduce how to port A. NET third-party library to iOS through Xamarin (iOS calls OpenXLive through Xamarin)

 

Summary

This article introduces the Mono-based Xamarin framework, supports using C # To develop iOS, android, Windows Phone, and Mac applications, and introduces Xamarin. iOS installation and configuration methods; describes how to use Xamarin. iOS SDK is developed in Windows and debugged on Mac remote host.

Related Article

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.