Bring your iOS Apps to Windows

Bring your code to Windows” is an important motto brought by Microsoft along with Windows 10 and Universal Windows Platform (UWP) releases.

In order to accomplish this, Microsoft plans to release a set of tools and platforms through which you can migrate iOS apps, Android apps, classic Win32-based apps and even web apps to UWP.

The most wanted toolkits are Windows Bridge for iOS and Windows Bridge for Android.

In this article we are going to talk only about how you can bring your Objective-C code to Windows, using Windows Bridge for iOS.

 

What is Windows Bridge for iOS?

Previously called “Project Islandwood”, Windows Bridge for iOS is a Microsoft project that enables you to develop Universal Windows Apps in Objective-C language using Visual Studio.

It also provides support for iOS API compatibility, allowing you to bring existing iOS apps to Windows.

Windows Bridge for iOS will be released in final form in the next months, but it is already available as an open-source project on GitHub, called WinObjC, with more or less known issues, which we are warned of.

According to a description on a Microsoft blog, the project is comprised of four components:

  1. Objective-C Compiler that converts Objective-C code into an Universal Windows App, and which will be included in Visual Studio 2015 as part of an update;
  2. Objective-C runtime, which provides features like message dispatch, delegation and automatic reference counting;
  3. iOS API headers/libraries. Currently, some features are missing from these libraries or they are not fully implemented, and Microsoft hopes that open-source community will help improve this project;
  4. Visual Studio IDE integration. A specific SDK and a tool used for importing Xcode projects which generates a .sln file after execution are now available.

The purpose of this early release is to gather feedback from the community and identify the most used iOS features, which are not supported by the SDK at this time.

 

How does it work ?

ios-windows-logo-629x325

Windows Bridge for iOS uses a customized compiler (clang+cl) that generates object files from Objective-C code objects, and links them together using Microsoft linker.

The Objective-C and C++/CX code can coexist in the same project and their functions can be called from one language to another using C or C++ interfaces. Since clang compiler does not recognize CX extensions used in Windows API calls, Microsoft suggests that developers should use projections/bindings, a way that Windows APIs are exposed in other programming languages.

For design, XAML and iOS controls can be combined using CALayers (which underlie iOS Views) as a wrapper over XAML elements.  This way, if you need to use an iOS UI control that is not yet supported by the Bridge, this mechanism enables you to use an Windows UI control XAML, wrap it in a CALayer, wrap that layer into a view, and place that view with all your other UIViews.

You can only create builds in debug mode at this time, and only for x86 and x64 processor architectures, and they will run on Windows Runtime. Also Visual Studio doesn’t provide support for creating UWP packages for these apps yet, so they cannot be distributed as Universal Windows Platform apps, for the moment.

 

What’s good to know before you start

WinObjC is available here for download and requires the following:

  • Windows 10;
  • Visual Studio 2015 with Windows Developer Tools installed.

Visual Studio 2015 Community Edition is available for free download here.

The following components must be selected during installation:

  • Visual C++ as a programming language;
  • Universal Windows App Development Tools;
  • Windows 8.1/Windows Phone 8.0/8.1 Tools.

Vsimporter tool is available from WinObjC’s archive folder “winobjc\bin”. This will help you convert Xcode projects into Visual Studio compatible projects, having Objective-C support.

The steps for using Vsimporter are:

  1. Unpack the archive;
  2. Move your Xcode project in “winobjc\samples”;
  3. Navigate to the project root folder using command prompt;
  4. Run vsimporter (c:\winobjc\samples\WOCCatalog> ..\..\bin\vsimporter.exe).

After following these steps, a .sln file for UWP project will be generated, and also other .sln files for Windows 8.1 or Windows Phone 8.1 projects.

A good way to start testing Windows Bridge for iOS capability is to run the samples from WinObjC archive. You can check WOCCatalog project which contains both iOS and XAML controls.

Some weaknesses identified in the Windows Bridge for iOS would be:

  • There are a few important features that cannot be ported yet from iOS like Autolayout, Storyboard, MapKit, AssetsLibrary, AddressBook, Ads, Objective-C annotations, Media Capture and Playback;
  • Swift language is not supported, whose popularity is growing in iOS applications development;
  • Compiler is not stable and it might crash. Also it is not opensource;
  • Builds for ARM are not supported yet.

Leave a Reply

Your email address will not be published. Required fields are marked *