Bringing your iOS app to Windows

What is the iOS bridge

The Windows Bridge for iOS (previously known as Project Islandwood, or WinObjC) is an OpenSouce project started and maintained by Microsoft primarily and by the community that allows developers to enable their existing iOS apps written in Objective-C to run on Windows 10 as Universal Windows Platform apps. What’s more, you can enhance those apps with UWP specific features like Live Tiles, Cortana and others.

How does it work

There are 3 main components that make the bridge:

Compiler

A custom clang compiler was written for this project to support compile Objective-C language to Windows bytecode.

Compatibility Libraries

To ensure that your apps can compile without any code changes, all of the APIs had to be written to conform to the Apple API definition but using the underlaying Windows libraries. I.E Imagine the CCLocationManager class, implemented using the Geolocator API.
Additionally, all the Windows API definitions have been described as headers from the Windows core winmd files to be made accessible to the Objective-C language.

Tools

There are a number of differences in the way an Xcode project is structured vs a Visual Studio project. The vsimporter, tool will generate the solution files and convert any assets to match the requirements for a Windows App, while other tools will compile the Storyboards and Xibs.
Last but not least, the Visual Studio syntax highlight plugin enables nice syntax highlighting for Objective-C in Visual Studio

Converting your first app

The way I see it there are 3 steps in porting an iOS app with the Windows Bridge for iOS

Convert

In the conversion step we are transforming our Xcode project into a Visual Studio solution file that we can open up with Visual Studio. This is relatively easy, and seldom creates any issues. Open a command prompt in the folder hosting your Xcode project and run the vsimporter.exe file from the WinObjC bin folder.
What you’ll get is a new folder that contains the generated UWP project and a Visual Studio Solution file that you can open up.

Compile

With the first step out of the way, we can now open the solution in Visual Studio and make sure we can actually compile. This step is a bit trickier than before and you’ll often need to make minor adjustments to ensure the solution compiles.
If there are API’s that were not bridged you will get compilation errors and need to find workarounds for those portion of the code (a lot of the APIs have been stubbed out, so they won’t give compilation errors, but there are still some missing). Also due to platform differences some structs or enums might be different and you’ll need to fix those (i.e. mach_timebase_info_data_t missing in Win32 use mach_timebase_info_t instead)

Runtime

By far the most complex task, and probably where most of the time will be spent in a conversion project is to ensure that at runtime, the project works and behaves as expected.
All those missing APIs that have been stubbed out will start to cause problems now, and some differences in how APIs are implemented can crash your app.
It’s too broad of a subject to try and describe in great detail, but the one thing that is worth mentioning at this point is that every time you encounter a runtime problem, your first instinct should be to find the root cause and see if this is a problem with your code or maybe a more general issue with the SDK itself, and if it’s generic enough, open an issue of the project’s page or better yet, open the issue, and try and fix it and open a pull request so that everyone else can benefit from it.

Enhance your app

If that wasn’t enough, after you have finished converting your app and everything works great on Windows, you can go a step further and start enhancing the app with Windows specific features like Cortana, Live-Tiles, Notifications, etc. You can do that with using Objective-C code since all the Windows APIs have been exposed and accessible from your ObjC code.

Help improving the bridge

Contributions to the project are always welcome. As I mentioned above, whenever possible, try and update the SDK rather to change your code if something does not look right. If you’re having an issue and the code works properly on iOS, that might be a good thing to update in the SDK for future conversions to just work.
Make sure you read the contribution guidelines.

Other resources

The main project page can be found on GitHub where there are links to great additional resources.

Check out the BUILD 2016 session - Getting started with the Windows Bridge for iOS

Lastly the Dev Center Bridge for iOS page.

Share Comments