We’re continuing with our series of getting started with Xamarin.Forms and Caliburn.Micro, check out these previous posts if you’re interested:
- Getting Started with Xamarin.Forms and Caliburn.Micro
- Configure Xamarin.Forms Droid to use Caliburn.Micro
Today, we’ll set up our Xamarin.Forms iOS project. Unlike the Droid project, we can get our project up and running with very few changes to the default template. So we'll start this post with configuring our Visual Studio instance to talk to our Mac.
And before you ask, unfortunately, although it's C# you absolutely need a Mac to compile and run the solution. On the plus side, you can do most of your development on your PC.
Verify Prerequisite Software on your Mac
You will need the following installed on your Mac:
- XCode 7+
- Xamarin Studio
- Xamarin.iOS SDK
Setup your Mac for Remote Access
Before you can configure Visual Studio to use your Mac as a Build Host, you'll need to configure your Mac to allow users to remotely login to your machine. You can get the full details following this post, but in short we can simply set up our mac using the following:
- Press Command ⌘ + Space to bring up Spotlight Search
- Type Remote Login to open Sharing
- Enable Remote Login and then specify Allow access for: All Users
Configure your Build Host
Now that your Mac will accept remote logins, we can now configure Visual Studio on the PC to use your Mac as a build host.
- From your PC, open our XF.CaliburnMicro project.
- In the toolbar, click on the Xamarin Mac Agent icon (also Tools –> iOS –> Xamarin Mac Agent):
- If your mac is running, it should appear in the dialog:
- Select your Mac, click Connect…
- You’ll be prompted to login, so provide the credentials you use when logging into the Mac
- Once connected, the toolbar changes colour and provides the option to launch the simulator:
Note this assumes that both the Mac and the PC are on the same network and that all required software is installed and configured for use.
Create and configure IoC Container
Now that we have our environment dependencies out of the way, we can turn our attention to modifying the template code to leverage Caliburn.Micro.
Similar to our Droid project, we need to set up our IoC container. For iOS, we do this by using a CaliburnAppDelegate which looks almost identical to the Application class we created for Android.
We then modify the AppDelegate to leverage our CaliburnAppDelegate, and change the start-up routine to use our App singleton.
Build and Run
To run your application, you’ll need to change the start project, select a target and the Device. Here I’ve selected XF.CaliburnMicro.iOS project, specified the iPhoneSimulator target and the iPhone 6s iOS 10.x simulator.
If everything worked, you should now see our Xamarin.Forms app backed by our Caliburn.Micro ViewModel.
So there you go! We’ve got both Android and iOS projects running. Our next post we’ll continue down this path and our Xamarin.Forms project to leverage the Universal Windows Platform which will target tablets, phones and PCs.