Xamarin C# Binding of a Cocoapods iOS SDK
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.
Join the DZone community and get the full member experience.Join For Free
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 installed. ** ?? 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 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. ** BUILD FAILED ** 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:
- 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
- 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:
** BUILD SUCCEEDED ** 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.
Note: You can follow the above steps to generate Xamarin C# binding for any Cocoapods iOS SDK.
Published at DZone with permission of Vidyasagar Machupalli , DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.