Monthly Archives: May 2016

Issue in the Xamarin.iOS binding library for Google Ads

This week, I had to work about an issue around the integration of Google Ads into a Xamarin.iOS application.

To integrate Google Ads in your application, Xamarin has published a binding library above the official iOS SDK (written in Objective-C). This library is available as a NuGet package.

After adding the package in your project, it’s very easy to use and in just few lines of code, you can create a search request and retrieve ads matching your criteria. The sample code below shows you how to achieve that (it has been simplified for brevity).

var request = new SearchRequest();
request.Query = "Xamarin Mobile Development";

var banner = new SearchBannerView(...); 
banner.LoadRequest(request);

Unfortunately, with the actual version of the NuGet package, this code won’t compile. The error is on line with the LoadRequest statement.

After some investigations, I’ve discovered the source of the problem. If you look at the official iOS SDK, you can see declarations like this :

@interface GADRequest : NSObject<NSCopying>
@interface GADSearchRequest : GADRequest

The GADSearchRequest class (aka. interface in the Objective-C terminology) inherits from the GADRequest class.

But if you look the source code of the binding library available on GitHub since few weeks (Xamarin has announced at Evolve 2016 that a lot of components are now open-source), you can see these declarations :

[BaseType(typeof(NSObject), Name="GADRequest")]
interface Request : INSCopying

[BaseType(typeof(NSObject), Name="GADSearchRequest")]
interface SearchRequest

As you can see, there is a difference compared to the official SDK, because the BaseType of the SearchRequest class is equal to NSObject rather than Request.

I’ve downloaded, modified and recompiled the source code with the following modification.

[BaseType(typeof(NSObject), Name="GADRequest")]
interface Request : INSCopying

[BaseType(typeof(Request), Name="GADSearchRequest")]
interface SearchRequest

With this simple modification, the LoadRequest statement is good and now, I’m able to compile and test the application successfully.

This issue has been submitted on GitHub and the pull request is waiting for approval.

In conclusion, if you encounter some compilation errors like this one (in this library or any other), take a look to the official SDKs, and compare the declarations with the binding library to ensure that everything is good.

How to remove the IOHIDLibFactory error when you start your Xamarin.iOS application in the simulator

When you will develop Xamarin.iOS applications, you will use the iOS simulator to test your application without having to use a real device like an iPhone or an iPad.

In Xamarin Studio (like in Visual Studio), the output window gives you some useful information to help you to debug your application (e.g. when you use Console.WriteLine(…) to print values).

When you start your application in the iOS simulator, it might happen that you see a lot of errors like this :

Error loading /System/Library/Extensions/IOHIDFamily.kext/Contents/PlugIns/
IOHIDLib.plugin/Contents/MacOS/IOHIDLib: dlopen(/System/Library/Extensions/
IOHIDFamily.kext/Contents/PlugIns/IOHIDLib.plugin/Contents/MacOS/IOHIDLib, 262):
no suitable image found. Did find: /System/Library/Extensions/IOHIDFamily.kext/Contents/
PlugIns/IOHIDLib.plugin/Contents/MacOS/IOHIDLib: mach-o, but not built for iOS simulator

Or also :

Cannot find function pointer IOHIDLibFactory for factory 13AA9C44-6F1B-11D4-907C-0005028F18D5 in CFBundle/CFPlugIn 0x7be04110 </System/Library/Extensions/
IOHIDFamily.kext/Contents/PlugIns/IOHIDLib.plugin> (bundle, not loaded)

It’s not a problem for your application and has no impact on it, but it’s often annoying to have a lot of errors in the output window, each time you start your application.

If you want to remove these errors, you just have to edit your iOS build settings, and change the linker behavior value from “Don’t link” to “Link Frameworks SDKs Only“.

Xamarin Studio - iOS Build Settings

Note that activating this option will increase the compile time of your application because the linker will have more work to do to generate your package.

[French] Integrate and use HockeyApp into your Xamarin applications

At the end of 2014, Microsoft has announced the acquisition of HockeyApp, a class leading service for mobile crash analytics and app distribution for developers building apps on iOS, Android, Windows Phone, Windows, OS X, etc…

Last week at Evolve 2016, the annual event about Xamarin products and technologies, some announcements were made and one of them concerns the first improvements integrated in HockeyApp, after the acquisition of Xamarin by Microsoft, earlier in March 2016.

If you speak french and re interested to discover what’s HockeyApp and how to integrate the service into your Xamarin applications, take a look at my new video available on Channel 9.