Chapter 2. Hello Platforms!

If you are familiar with developing applications using Visual Studio on Windows, then using Xamarin Studio should be very straightforward. Xamarin uses the same concept of a solution that contains one or more projects, and there are now several new project types for iOS and Android applications. There are also several project templates to jumpstart your development of common applications.

Xamarin Studio supports several out of the box project types including standard .NET class libraries and console applications. You cannot natively develop Windows applications on a Mac with Xamarin Studio, but you can certainly develop the shared code portion of your application in Xamarin Studio. We'll elaborate on sharing code in the later chapters, but keep in mind that Xamarin enables you to share a common C# backend between nearly any platforms that support C#.

In this chapter, we will cover:

  • Hello World for iOS
  • Apple's MVC pattern
  • Xcode and storyboards
  • Hello World for Android
  • Android activities
  • Xamarin's Android designer

Building your first iOS application

Launch Xamarin Studio and start a new solution. Just like in Visual Studio, there are lots of project types that can be created from the New Solution dialog. Xamarin Studio, formerly MonoDevelop, supports the development of many different types of projects such as C# console applications targeting the Mono runtime, NUnit test projects, and even other languages besides C#, such as VB or C++.

Xamarin Studio supports the following project types for iOS:

  • iPhone or iPad project: This is the default project targeting an iPhone or iPad using XIB files for user interface layout. This is an older format that is fine to use, but doesn't have as many options as storyboards.
  • iPhone or iPad storyboard project: This is a project that uses storyboards for laying out the UI. Storyboards were released with iOS 5 and are the more modern ways of modifying UI layouts.
  • Universal project: This is a project that can support either XIB or storyboards. Supports both iPad and iPhone in the same application.
  • iOS binding project: This is an iOS project that can create C# bindings for an Objective-C library.
  • iOS unit test project: This is a special iOS application project that can run NUnit tests.
  • iOS library project: This is a class library used within other iOS application projects.

To get started, navigate to iOS | iPhone Storyboard and, create a Single View Application in the directory of your choice, as seen in the following screenshot.

Building your first iOS application

You'll notice that several files and folders are automatically created from the project template. These files are as follows:

  • Resources: This directory will contain any images or plain files that you want to be copied directly to your application bundle.
  • AppDelegate.cs: This is Apple's main class that handles application-level events in your app.
  • *ViewController.cs: This is the controller that represents the first screen in your app. It will have the same name as your project.
  • Info.plist: This is Apple's version of a manifest file that can declare various settings for your application.
  • Main.cs: This file contains the standard entry point for a C# program: static void Main(). It's most likely that you will not need to modify this file.
  • MainStoryboard.storyboard: This is the storyboard definition file for your application. It will contain the layouts for the views in your app, list of controllers, and the transitions for navigating throughout your app.

Now, let's run the application to see what we get by default from the project template. Click on the large play button in the top-left corner of Xamarin Studio. You will be greeted by the simulator running your first iOS application as seen in the following screenshot:

Building your first iOS application

So far, your app is just a plain white screen, which is not very exciting; but, let's get a little more background on iOS development before moving forward.

Depending on your application's minimum iOS target, you can also run the application on an iOS 6 or iOS 7 simulator. Apple also provides simulators for iPad and different devices such as the iPad, iPhone 4, and iPhone 5. It is also important to know that these are simulators and not emulators. An emulator will run an encapsulated version of the mobile OS (just as Android does). Emulators generally exhibit slower performance but give you a closer replica of the real OS. Apple's simulators run in native Mac applications and are not true operating systems. The benefit is that they are very fast in comparison to Android emulators.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.15.235.196