Using Good Dynamics SDK with Xamarin 101

Using Good Dynamics SDK with Xamarin 101

Both Good Dynamics and Xamarin are useful products that greatly simplify some of the larger hurdles in mobile application development such as learning Objective-C and implementing mobile encryption and security management.  Xamarin is a mobile application development framework that allows you to develop fully native, cross-platform mobile applications using C# and Microsoft.NET.  Good Dynamics is a mobile security provider that allows organizations to embed security into their mobile apps and provides mobility management as well.  This powerful combination allows companies to build secure native cross-platform mobile applications with nothing more than a few .NET developers.

This blog posts serves as an introduction to the two platforms and a guide on how to combine them into a basic Xamarin iOS application that uses the Good SDK.  The guide will cover everything from account registration, installation, and step-by-step implementation instructions.



This section of the blog post will walk you through the steps to become a Xamarin developer and create a simple Xamarin iOS application.

In order to build a Xamarin application, you must have a Xamarin account and a paid license.  You can create an account here and view the different license prices here.

Once you are all registered, you can download Xamarin which comes with the Xamarin Studio IDE or Xamarin for Visual Studio.

Although Xamarin provides the ability to create iOS apps using C#, building an application still requires a Mac.  Xamarin’s development environment provides the options of writing and building your application within Xamarin Studio on a Mac or writing your application in Visual Studio on Windows and building it on a Mac.

For this guide, we will be using Xamarin Studio on a Mac.  To create a new iOS project:

  1. File > New > Solution, a new project wizard will appear.
  2. Under iOS on the left, select App, then under General Single View App.  The type of app doesn’t matter. We just picked Single View so you can see something on a device.ss2
  3. Step through the wizard using values of your choice

The result is a Xamarin iOS project that builds into an iOS app with a blank white page.  You can run this on a device or emulator.


Good Dynamics

This section of the blog post will walk you through the steps to implement the Good Dynamics iOS SDK into your Xamarin iOS project.

Because the Good iOS SDK is meant to be used in an Objective-C project, we must use the Xamarin Binding.  A Xamarin Binding is created from an iOS SDK to allow you to use that SDK in your Xamarin project.  Think of it like a technology bridge between the .NET-based Xamarin and the Objective-C-based Good Dynamics iOS SDK.

In order to download the Good Dynamics iOS SDK, you must have a GDN (Good Developer Network) account.  Sign up here.

The next requirement to setting up Good Dynamics is to access the Good Dynamics admin portal.  The admin portal allows a designated company administrative role complete access to deployment, management, adoption of Good Dynamics solutions across users and their devices.  Access to the admin portal is required for developing Good embedded apps.  For example, the Good admin portal issues access keys required to log into those apps.  In order to access the admin portal, your company must be a customer of Good and request additional membership permissions.


Including the Good Dynamics Project

Once you have verified your email and have access to the Good admin portal, you may begin implementing Good into your Xamarin iOS app:

  1. Get the Good Dynamics iOS binding project.
    1. Visit the Downloadspage and download “Bindings for Xamarin”.
    2. Unzip the download, then unzip the iOS folder.
    3. Copy that folder into your Xamarin solution directory.
  2. Include the Good Dynamics iOS binding project in your Xamarin project.
    1. In your solution, add an existing project by browsing to the GoodDynamics.iOS.csproj file and selecting it.
    2. In your iOS app project, reference the GoodDynamics.iOS project by editing the project references.

Implementing the Good Dynamics SDK

Now that you have all the libraries you need, it’s time to code!  The first thing to do is to change your AppDelegate class so that it extends GDiOSDelegate instead of UIApplicationDelegate.  Make sure to include “using GoodDynamics” at the top so you can reference the GDiOSDelegate.  Don’t worry, GDiOSDelegate extends UIApplicationDelegate so your app won’t break.

The GDiOSDelegate is the base requirement for an iOS app to be considered a GD Application.  Because the app delegate controls what happens between the application code and the iOS device’s application management system, Good has provided us their own custom AppDelegate that intercepts commands made from the application to the device to apply its security logic.

Next, we need to initialize the Good Library.  The Good Library is the central hub for all Good functionality.  This is managed with a GDLibrary property in the AppDelegate.  The FinishedLaunching method is where all the Good Library setup goes:

GDLibrary = GDiOS.SharedInstance();
  • This returns a reference to the GD infrastructure connection status object.
Delegate = this;
  • This command binds the current AppDelegate to the GD Library. This allows it to know about the delegate to send callbacks to.
  • This is an optional command that takes attempts to log the user in through Good right when the app starts up. This will only work when the user has previously verified their credentials with Good through the app.  Even though this is optional, it is still recommended to use this so the user doesn’t get tired of unnecessarily logging in.
Window = GDLibrary.GetWindow()
  • This is the final command that actually displays the Good user interface that the GD Library has provided.
namespace GoodHelloWorld
     [Register ("AppDelegate")]
     public class AppDelegate : GDiOSDelegate
         public GDiOS GDLibrary { get; private set; }
         public override UIWindow Window {
         public override bool FinishedLaunching (UIApplication application, NSDictionary launchOptions)
             GDLibrary = GDiOS.SharedInstance();
             GDLibrary.Delegate = this;
             Window = GDLibrary.GetWindow();
             Window.MakeKeyAndVisible ();
             return true;

The next piece of code we need is an event handler for events that come from the Good Dynamics SDK.

public override void HandleEvent (GDAppEvent anEvent)
    switch (anEvent.Type){
    case GDAppEventType.Authorized:
        OnAuthorized (anEvent);
    case GDAppEventType.NotAuthorized:
        OnNotAuthorized (anEvent);

This method fires when the Good SDK sends an event response to the application.  What type of event happens is specified by the GDAppEvent argument.  There are many types of events that Good can send back, but for now we are just going to handle the events for logging in.  In the code sample above, the switch statement keys off anEvent.Type which indicates what type of event was sent back.  For this example, an event of type GDAppEventType.Authorized is returned when the user has securely logged in through the Good wrapper.

private void OnAuthorized(GDAppEvent anEvent)
    switch (anEvent.Code) {
    case GDAppResultCode.ErrorNone:
        Debug.Assert (false, "Authorized startup with an error");


If your Xamarin app requires users to login, your next move would be to call your application’s login method; in this case that is OnAuthorized().  This way, securely logging in with Good also logs into your application seamlessly.

Configure the Application using Good Control

Now that the code is complete, the last step is to register our app with Good.  In these steps we will access Good Control to set up and manage our app.  Good Control is a web-based management console that can be setup and configured through the Good Admin Portal.  Typically, the person who keeps track of Good apps, users and devices uses Good Control.

  1. Open up an internet browser, and navigate to the url of your company’s Good Control.
  2. Click Manage Apps on the left and then click Add App on the right.
  3. A popup will appear asking for what type of app to create. Because we are doing this for development purposes only, select “GD Entitlement ID and Version”.
  4. Next, fill out the details of the app.  The values here don’t really matter. Just make sure that the GD Entitlement ID is of the form “something.companyname.appname” where something, companyname and appname can be anything in lowercase characters.  Click Add App to complete the process.
  5. The next step is to grant your user access to log into the application.  You can manage users by click the Users and Groups section under Users on the Dashboard.  Click on the user you wish to grant access to.
  6. Next, you will see the control panel for the selected user.
    1. Click Apps on the banner, then click Add More to add a new app.
    2. A popup will appear that will help you select the app you want to add. You can select it by either typing in the name of the app in the textbox or selecting it from a list of apps below it.  Click OK to finish.
  7. At this point, your user can log into your fully configured Good app.  The last step is to give your user an Access Key that will allow your user to log in for the first time.  To grants an Access Key:
    1. Click Access Keys on the banner.
    2. Click new Access Key to generate a new one.
    3. The new Access Key will appear on the screen and it will also be sent to your email.
    4. Keep this access key handy for when you are ready to log into your Xamarin application.

Configure the Good Application in Xamarin

  1. Now, back in Xamarin Studio, locate Info.plist and open it up.  The Info.plist file is a file that contains important metadata about your application.  The Good Dynamics SDK looks at this file to make sure that this app is the one that corresponds with the application you set up in Good Control.  There are a few lines to add here:
    1. GDApplicationID: This needs to match your GD Entitlement ID.
      1. Note that this must also match Bundle identifier.
    2. GDApplicationVersion: This needs to match the GD Entitlement Version.
    3. Under URL types > Item 0 > URL identifier > URL Schemes, add the listed 3 items.
      1. Make sure Item 0 and Item 1 match the GDApplicationID.ss11
  2. The last step is to add some additional linker arguments that will help the Good Dynamics iOS SDK work with your Xamarin project.  Because the SDK is essentially a C++ library, it gets compiled and linked differently than typical Xamarin libraries do.  To do this in Xamarin Studio:
    1. Navigate to your project options.
    2. On the left side, click “iOS Build” under “Build”.
    3. Locate Additional Options – Additional mtouch arguments at the bottom and type the following:
      -cxx --registrar:static --linkskip=System.Core --linkskip=System --linkskip=mscorelib --gcc_flags="-stdlib=libstdc++ -framework QuickLook  -framework LocalAuthentication -framework SystemConfiguration -framework Security -framework MobileCoreServices -framework QuartzCore -framework CoreTelephony -framework MessageUI -framework AdSupport -B ${ProjectDir}"
    4. Click OK.

Running the Application

The result of these steps should produce an application that takes you to this screen:

This is the initial login screen you see when attempt to access a Good embedded app for the first time.  Here is where you enter your email address and your access key that you generated previously.  The access key is not case sensitive.  Sometimes an access key will have capital letters because the capital letters are easier to read.  Once the access key is used, it expires.

If your credentials were successful, you will be directed to this screen:

This is the final Good setup screen that allows you to enter your own password to access the app without requiring an access key each time.  This password will be good until you uninstall the app.  Successfully doing this will take your application!

That is it!  You now have a Good embedded Xamarin application!  You can now use this without the worry of your application data being compromised.  Stay tuned for future blog posts that will demonstrate some of the more powerful security features of Good Dynamics.

Our mobility consulting professionals have extensive experience developing enterprise mobile apps utilizing Xamarin, Xamarin.Forms, and the Good Dynamics SDK to accelerate the creation of high quality, highly-secure, mission-critical enterprise apps.  Contact us for more information on how we can work with you to build highly secure, cross-platform mobile applications.

Phone: 312-602-4000
222 W. Adams
Chicago, IL 60606
Show Buttons
Share On Facebook
Share On Twitter
Share on LinkedIn
Hide Buttons