Windows Bridge for iOS (WinObjC)

repository·develop·Indexed 27 days ago

https://github.com/microsoft/winobjc

The Windows Bridge for iOS (WinObjC) enables developers to create Universal Windows Platform (UWP) applications by reusing existing Objective-C code and iOS APIs within Visual Studio. It includes tools like vsimporter.exe for importing Xcode projects, a specialized OpenAL-soft shared library for Windows Store Apps and Windows Phone 8.0+, and integration guides for the Application Insights SDK C++.

Tokens
15.7K
Snippets
26
Records
104
Agent score
91%

What's inside WinObjC

  1. Overview of OpenAL-soft for Windows Store App/Windows Phone 8.0+

    develop

    This project provides an OpenAL-soft shared library specifically for Windows Store Apps and Windows Phone 8.0+. It is a fork of the standard OpenAL-soft to add support for these platforms. It includes two back-ends:

    • Xaudio2: The default back-end.
    • WASAPI (Windows Audio Session API): An alternative back-end.
  2. Understand NSInvocation design specification

    develop

    NSInvocation is a Foundation class that provides an object representation of a method call by encapsulating a target, a selector, and a pack of arguments. In the Windows Bridge for iOS, NSInvocation is designed to lay out arguments at runtime based on the Objective-C method signature, ensuring the internal memory layout matches the platform's preferred argument frame (registers, stack, etc.).

    This design allows for:

    • Efficient argument dispatching with minimal copying.
    • Reversible memory layouts, enabling forwardInvocation: to quickly package partially-evaluated method dispatches into a boxed NSInvocation object.
  3. Use PropSchemaGen to generate Visual Studio Property Schema XML

    develop
    PropSchemaGen is a tool designed to be used exclusively with ClangCompile. It generates an XML file compatible with Visual Studio's PropSchema interface. This tool enables a workflow where XML is generated from code via reflection, rather than the standard Visual Studio approach of generating .NET tool components from existing XML files.
  4. Convert ObjC middleware to WinRT Components using ObjC2Winmd

    develop

    The ObjC2Winmd tool converts Objective-C middleware into WinRT Components (.winmd and .dll). It wraps Objective-C types into WinRT types and vice-versa.

    To use the tool, follow these steps:

    1. Use VSImporter (from WinObjC.Tools) to import your Objective-C middleware to Islandwood.
    2. Configure public headers in the generated .vcxproj file.
    3. Add necessary Doxygen-style annotations to your public header files to ensure correct type marshalling.
    4. Rebuild the solution. The WinRT wrapper files will be generated under the <Middleware Name>WinRT.vcxproj project, producing the final *.winmd and *.dll files.
  5. Handle Toast Notification Actions in iOS apps

    develop
    When using the Windows Bridge for iOS, you can leverage Windows Toast Notifications within your iOS-based application. To respond to user interactions with a Toast Notification (such as clicking a button or submitting input), you must implement the application:didReceiveToastAction: delegate method in your UIApplicationDelegate implementation. This allows the app to be activated in the foreground with the parameters provided by the Toast Action.
  6. Install WinObjC prerequisites and tools

    develop

    To use the Windows Bridge for iOS, ensure your environment meets the following requirements:

    System Requirements

    • Windows 10, build 10586 or higher.
    • Visual Studio 2017 with Windows developer tools.

    Required Visual Studio Components: Selecting the 'Universal Windows Platform development' workflow installs most requirements. However, you must also install the Mobile development with .NET (Xamarin Tools) workflow due to a Nugetizer bug.

    Specific components include:

    • Visual Studio Core Editor
    • Nuget Package Manager
    • C# and Visual Basic Roslyn compilers
    • Static analysis tools
    • Windows 10 SDKs (10.0.14393.0, 10.0.10240.0, 10.0.10586.0)
    • Visual Studio C++ core features
    • VC++ 2017 v141 toolset (x86, x64)
    • Visual C++ compilers and libraries for ARM
    • Visual C++ runtime for UWP
    • MSBuild
    • Windows Universal CRT SDK
    • Standard Library Modules
    • VC++ 2015.3 v140 toolset (x86, x64)
    • Windows Universal C Runtime

    Command Line Tools

    If you are importing an existing Xcode project, you need Chocolatey and winobjc-tools. Install or upgrade the tools using PowerShell (Admin):

  7. Compress images with cjpeg

    develop

    Use cjpeg to compress image files (PPM, PGM, BMP, Targa, or RLE) into JPEG format.

    Usage Patterns:

    • Unix-like systems: cjpeg [switches] [imagefile] > jpegfile (writes to stdout).
    • Non-Unix systems: cjpeg [switches] imagefile jpegfile (explicit input/output).
    • Universal (Script-friendly): cjpeg [switches] -outfile jpegfile imagefile.

    Common Switches:

    • -quality N: Set quality from 0 (worst) to 100 (best). Default is 75. For compatibility at low quality, use -baseline.
    • -grayscale: Create a monochrome JPEG from color input.
    • -rgb: Create an RGB JPEG (suppresses YCbCr conversion).
    • -optimize: Performs entropy encoding optimization (smaller files, more memory/time).
    • -progressive: Creates a progressive JPEG (better for slow connections).
    • -scale M/N: Scales the output image by factor M/N.
    • -smooth N: Smooths input to eliminate dithering noise (N: 1-100).
  8. Initialize Session Tracking in App.xaml

    develop

    To enable automatic session tracking and page view collection, initialize the SessionTracking object in your application's lifecycle.

    1. In App.xaml.h, declare a member variable: ApplicationInsights::CX::SessionTracking^ m_session;

    2. In App.xaml.cpp, use the ApplicationInsights::CX namespace and initialize the session in the App::App() constructor: m_session = ref new ApplicationInsights::CX::SessionTracking();

    3. Once the root Frame is created (typically at the end of App::OnLaunched), initialize the session with your Instrumentation Key: m_session->Initialize(this, rootFrame, iKey);

  9. Configure public and private headers in .vcxproj

    develop

    To ensure the tool processes your headers correctly, you must explicitly mark them in the generated .vcxproj file.

    Enable Public Header Exporting

    Search for the <Keyword>IslandwoodProj</Keyword> tag in your .vcxproj file. Immediately after it, add the following line:

    <ExportPublicHeaders>true</ExportPublicHeaders>

    Mark Individual Headers as Private

    To mark a specific header as private, find the header's entry in the .vcxproj file and add the <PublicHeader> tag with a false value:

    <ClInclude Include="MyHeader.h">
      <PublicHeader>false</PublicHeader>
    </ClInclude>
    <!-- Example of marking a header as private -->
    <ClInclude Include="MyHeader.h">
      <PublicHeader>false</PublicHeader>
    </ClInclude>