Over a million developers have joined DZone.

Xamarin C# Binding of a Cocoapods iOS SDK

This article shows how to use Objective Sharpie to set up a Xamarin C# Binding of a Cocoapods iOS SDK.

After my endeavor with Xamarin.Android Bindings and Xamarin Apps with IBM MobileFirst, I received an interesting requirement from my colleague Chethan. He wants Xamarin C# binding of our IBM MobileFirst Foundation Objective-C APIs. I thought this is an opportunity to try something new and accepted the challenge.

I immediately started exploring to find something called Objective Sharpie on Xamarin's Objective-C binding page. While reading through the documentation, I found one more interesting scenario which will simplify my binding effort i.e., Effective version 3.0, Objective Sharpie supports binding CocoaPods.

Yay!! We already have IBM MobileFirst Platform Foundation iOS SDK available on Cocoapods and now it's time to follow the steps mentioned in the documentation.

The first step is to download, set up, and update objective Sharpie. Once we are all good, our journey begins towards achieving Xamarin C# binding. Run the below command in a terminal.

$ sharpie pod init ios IBMMobileFirstPlatformFoundation

If all goes well, here's the expected output:

Setup completed

** Searching for requested CocoaPods ...

** Working directory:

**   - Writing Podfile ...

**   - Installing CocoaPods ...

**     (running `pod install --no-repo-update`)

Analyzing dependencies

Downloading dependencies

Installing IBMMobileFirstPlatformFoundation (8.0.2016061012)

Generating Pods project

Sending stats

Pod installation complete! There is 1 dependency from the Podfile and 1 total pod


** ??  Success! You can now use other `sharpie pod` commands.

Success! There's one more command before we see the binding:

$ sharpie pod bind

Possible Errors & Their Fixes

Commands can go good and at the same time can error out. In my case, there were a bunch of errors:

xcodebuild[56779:791166] [MT] PluginLoading: Required plug-in compatibility UUID ACA8656B-FEA8-4B6D-8E4A-93F4C95C362C for plug-in at path '~/Library/Application Support/Developer/Shared/Xcode/Plug-ins/Unity4XC.xcplugin' not present in DVTPlugInCompatibilityUUIDs

xcodebuild[56779:791166] Failed to load plugin at: /Users/VMac/Library/Application Support/Developer/Shared/Xcode/Plug-ins/Unity4XC.xcplugin, skipping.  Reason for failure: *** -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[0]

User defaults from command line:

IDEDerivedDataPathOverride = /Users/VMac/Pods/sharpie-build

=== BUILD TARGET Pods-ObjectiveSharpieIntegration OF PROJECT Pods WITH CONFIGURATION Release ===

Check dependencies

Code Sign error: No code signing identities found: No valid signing identities (i.e. certificate and private key pair) were found.


The following build commands failed:

Check dependencies

(1 failure)

error: xcodebuild did not run successfully (exit code: 65)

No worries! We can fix the error in multiple ways:

  1. As the issue is with the unity plugin, we can uninstall unity from the Mac and install again. If that doesn't fix the error, then
  2. Navigate to ~/Library/Application Support/Developer/Shared/Xcode/Plug-ins/ folder and delete the plugin if the plugin is not in use.

There's also a chance that the Cocoapods iOS SDK expects a lower iPhoneOS SDK like the error below:


Submitting usage data to Xamarin...

Submitted - thank you for helping to improve Objective Sharpie!

Done. Exiting with error code 1.

error:  framework requires SDK 'iphoneos9.2' which is not installed. You may need a newer Xcode.

In reality, we may see an SDK version higher than the one mentioned in the error description and our Xcode is up to date. To fix the error:

  • Download the version of Xcode with the SDK version you are looking for.
  • Right click on the Xcode_ .dmg file and Select "Show Package Contents" from the menu.
  • Now navigate to Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/ and copy iPhoneOS<Version_number>.SDK folder.
  • Paste the copied folder to /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/

If all goes well, You should see a lengthy output on the terminal + a couple of warnings with the word Done. You should see the below binding files once you navigate to the base folder.Binding output

Note: You can follow the above steps to generate Xamarin C# binding for any Cocoapods iOS SDK.

xamarin ,ibm mobilefirst ,xamarin.ios ,cocoapods ,binding ,ios ,sdk ,objective-c

Published at DZone with permission of Vidyasagar Machupalli, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}