Rss

Using the Good Dynamics SDK with MonoTouch

Containerization and authentication using Good Dynamics came up as a requirement on a project recently. The project is an iPad app, so no problem…except…the project is written entirely in C# using MonoTouch/Xamarin.iOS 2.0. There is not much information out there on bringing GD into MonoTouch, and not really any strong success stories. I think there are folks out there having some success with it, but they must not be sharing that information.

Maybe I’m asking for Good’s lawyers to get on my case here, but I think posting this stuff is within the bounds of the agreement I “signed” to acquire access to the Good Dynamics Network. Just in case, if you don’t already have an account there, go sign up quick. If you don’t have an account, please stop reading. 😉

Good Setup Splash Screen iPad #1
After several hours of tinkering, I was finally greeted by this screen. It probably took much longer than it needed to, but I have no experience with MonoTouch bindings (I’ve got plenty of C# and Objective-C experience individually, though).

I started with the only code I could find out there, the wrapper and test project solution on Gareth Hughes’ GitHub repository. It had everything I needed to get started, though having the Good Dynamics SDK also helped. From there I explored the header files to see how the methods were defined and then added a few extra bindings.

From there, I did several things:

  • Refreshed the library binary from the current download
  • Added the GD.bundle to the project so the Good GUIs would work correctly
  • Added the required entries to the Info.plist, as noted in the Good Application Migration Guide
  • Added several more bindings
  • Used the initialise selector instead of the longer (and more preferred) syntax for initializing the Good framework
  • Successfully authenticated using the GD GUI in Simulation mode
  • Added the Mono.Data.Sqlite_2.0 source files from the latest Mono release, moved it to a new namespace (GD, the same as the binding), and altered it to use the GD Secure Database API (note: this breaks the ability to open UTF16 databases). There is an ADO.NET-compatible connector for the encrypted SQLite database used by Good in this binding.

Things not yet done:

  • Use the binding in live (not simulated) mode
  • Fully test the secure database implementation
  • The preferences UI will not display. The bound call to showPreferencesUI: returns false and nothing happens. I’ve tried passing a reference to a navigation controller and passing a null reference.
  • Fully wrap the GDiOS API.

Good Splash Screen iPad #2

Here’s the project. I don’t know jack when it comes to using GitHub, so this is a plain old zip file. Also note: launching the application from the debugger seems to clobber the database, but if you launch the app from the springboard, previously saved data appears.

GDTest.zip

Comments (4)

  1. Hi Aaron, great post, many thanks.

    I had a lot of fun with the Good phonegap API but I’ve now moved onto GD and Xamarin. I tried to do an out of the box ‘app wrap’ using the Good Dynamics App Wrapping server but that didn’t want to play ball with a Xamarin built ipa file so I started to look at linking the native SDK and found your artice.

    I believe the Good guys aren’t dedicating anytime to this so it’s great to have people like you on board. Your example runs fine in the simulator and as you said, at the time, you hadn’t got it running in live. I’ve had an attempt but I keep getting MT5202 Native linking failed errors. Did you ever manage to get it a release .ipa file built? Thanks in advance for any direction you can give.

    Stephen

    • Hi Stephen,
      Thanks for commenting! Sorry for the delay, things were getting really intense with another part of this project right about the time that you commented. I’m circling back to GD integration now and I have some information that might help you.

      First, you are correct that Good is not interested in supporting MonoTouch/Xamarin. I spoke with a Good engineer on the phone and he told me that I was the second customer to ask about GD support for Xamarin, versus several questions *per day* on PhoneGap or native.

      I understand that, I guess, since those are free tool chains, whereas I think many developers have trouble justifying the $1k price of Xamarin to themselves or their managers. Especially because it isn’t even supported by the Good Dynamics platform. #chickenoregg?

      So anyway, enough of the soapboxing, let’s talk solutions. I’m guessing you’re getting errors similar to this:

      error MT5210: Native linking failed, undefined symbol: std::string::find_first_of(char const*, unsigned long, unsigned long) const. Please verify that all the necessary frameworks have been referenced and native libraries are properly linked in.

      I think Good changed their SDK since I originally wrote the article, because I didn’t have any trouble then. I understand that they had to make some significant overhauls for iOS 7, so I guess it’s no surprise. Anyway, I fought with this for probably 8 hours. I had to get my hands pretty dirty, but I’m building and connecting to a live GC/GP setup successfully now.

      The problem is that the GD SDK appears to be linked against libstdc++, but the clang++ compiler by default uses libc++. In fact, it will actually substitute libc++ in if you ask for libstdc++, so adding libstdc++ to your LinkWith attribute in your binding project won’t make any difference.

      Here’s my updated LinkWith attribute (I pulled in libraries and frameworks as specified in the Good docs and the GD Xcode project template:
      [assembly: LinkWith ("GD.a", LinkTarget.ArmV7 | LinkTarget.Simulator, "-lstdc++ -lz", ForceLoad = true, IsCxx=true, Frameworks = "CoreData CoreGraphics CoreTelephony SystemConfiguration AdSupport Security Foundation CoreFoundation UIKit QuartzCore")]

      That will at least get rid of any unknown symbol errors for references to frameworks. You have to get a little dirty to fix the references to libstdc++. To resolve this, you need to instruct clang++ to use libstdc++ as the standard library instead of libc++. This is done by adding -stdlib=libstdc++ to the clang command line.

      Since clang is not directly executed by Xamarin studio, it must be passed through the invocation of mtouch. Open the Project Options for your application project. Under Build, click iOS Build. At the bottom of the General tab is an Additional Options section. In the Additional mtouch arguments box, put:
      --gcc_flags="-stdlib=libstdc++"
      You will need to put this in for each configuration and platform. I didn’t see any easy way to supply it once for everything. But after a little copy-paste, click OK and you should be building successfully!

      Hope this helps!
      Aaron

      • Hi Aaron, sorry I missed the notification that you had replied so sorry for the long delay in responding. We’ve had some great success with Good Dynamics and Xamarin, the only thing that doesn’t seem to work is sending files to GFE. Did you ever get it all working? If not feel free to email be and hopefully I can help out. The next challenge will be to get it all working on Android :-O.

        Cheers Aaron!
        Steve

  2. Finally Good are supporting Android and iOS Bindings for Xamarin

    https://community.good.com/docs/DOC-4811

    Cheers Aaron!

    Steve

Leave a Reply

Your email address will not be published. Required fields are marked *