Xamarin.iOS Binding for an Existing iOS Objective-C Library with Objective Sharpie
Vidyasagar Machupalli takes us step-by-step through generating a Xamarin.iOS binding for an existing iOS Objective-C library with Objective Sharpie.
Join the DZone community and get the full member experience.
Join For FreeThese days a new phase has crept into my developer life and I call it "generating Xamarin.iOS binding for Objective-C libraries". After tasting success by generating Xamarin C# binding of a Cocoapods iOS SDK using Objective Sharpie, a new request hoped-in from the MobileFirst Platform Foundation team.
This time,the task is to generate Xamarin.iOS binding for Bluemix Push Notification Service Client SDK-Push Notification and engagement services that you will love. As I am well versed with binding creation, I thought it would be a cakewalk. Following the same steps as mentioned in the blog post, I ended up generating a definition binding for:
IBMMobileFirstPlatformFoundation (Dependent class)against IBMMobileFirstPlatformFoundationPush.
After a bit of research, here's how we achieved our goal.
Just a quick note before we start: Objective Sharpie is a command line tool to help bootstrap the first pass of a binding. It works by parsing the header files of a native library to map the public API into the binding definition (a process that is otherwise done manually). Objective Sharpie does not create a binding by itself, but it can help get you started!
Step 1:
Install and Setup Objective Sharpie. Download here.
Tip: Use the sharpie Update
command to Update to the Latest Version.
For any assistance, while using Objective Sharpie, use sharpie -help
which shows you all the commands and options available.
Vidyasagars-MacBook-Pro:~ VMac$ sharpie -help
usage: sharpie [OPTIONS] TOOL [TOOL_OPTIONS]
Options:
-h, -help Show detailed help
-v, -version Show version information
Telemetry Options:
-tlm-about Show a detailed overview of what usage and binding
information will be submitted to Xamarin by
default when using Objective Sharpie.
-tlm-do-not-submit Do not submit any usage or binding information to
Xamarin. Run 'sharpie -tml-about' for more
information.
-tlm-do-not-identify Do not submit Xamarin account information when
submitting usage or binding information to Xamarin
for analysis. Binding attempts and usage data will
be submitted anonymously if this option is
specified.
Available Tools:
xcode Get information about Xcode installations and available SDKs.
pod Create a Xamarin C# binding to Objective-C CocoaPods
bind Create a Xamarin C# binding to Objective-C APIs
update Update to the latest release of Objective Sharpie
verify-docs Show cross reference documentation for [Verify] attributes
docs Open the Objective Sharpie online documentation
Step 2:
Open Terminal and run the below command:
sharpie xcode -sdks
sdk: appletvos9.2 arch: arm64
sdk: iphoneos9.3 arch: arm64 armv7
sdk: iphoneos9.2 arch: arm64 armv7
sdk: macosx10.11 arch: x86_64 i386
sdk: watchos2.2 arch: armv7k
Step 3:
For this step, we need a static library with all the required.h and.m files. If you don't have one, follow the instructions here to create.
With an assumption that all the required header files (.h) including the Main Header file (in our case IBMMobileFirstPlatformFoundationPush.h)
are sitting in the same folder, Run the below command on Terminal with appropriate output, namespace, SDK information based on your expected output.
sharpie bind --output=IBMMobileFirstPlatformFoundationPush --namespace=IBMMobileFirstPlatformFoundationPush --sdk=iphoneos9.2 [full-path-to-STATIC LIBRARY FOLDER on your machine]
Note: In my case, I can use iOS 9.2 or iOS 9.3 As a parameter for --sdk. Please use the appropriate SDK version based on the output.
You should see the below files under the folder where you are running all the above commands.
Opinions expressed by DZone contributors are their own.
Comments