Xamarin.iOS Binding for an Existing iOS Library with Objective Sharpie
These 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.
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!
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]
-h, -help Show detailed help
-v, -version Show version information
-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
-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
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
Open Terminal and run the below command:
sharpie xcode -sdks
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.