ArcGIS Mobile iOS and monotouch?

3767
6
Jump to solution
03-14-2012 04:06 AM
RichardFisher
New Contributor III
Is it possible to mix ESRI mobile iOS application development with http://xamarin.com/monotouch to gain cross-platform ESRI apps between iOS and Android? Related would be the Android link http://xamarin.com/monoforandroid.

It would be very useful if one could successfully combine the monotouch / monoforandroid SDK with the ESRI mobile SDK for both environments and I was wondering if anyone had tried or used this approach to simplify development?
0 Kudos
1 Solution

Accepted Solutions
by Anonymous User
Not applicable
The short answer, it is possible. As Monotouch is a cross compiler and if you want to use C# to write code that becomes a binary, you can do that, yet it takes a little work to set it up. Yet if you are serious to use MonoTouch I would recommend first to create a simple app with a map. There is an old sample you can use to start:

http://www.arcgis.com/home/item.html?id=4d292f8a378b4a3ca67178974d9eeed3

NOTE: This is a proof of concept only!

Yet you'll have to update the ArcGIS.a library to the 2.1 How to do that is here to create the interface for the library: http://wiki.ios.xamarin.com/HowTo/Interop/Consuming_3rd_Party_ObjC_Libraries

The binding of the library can be the most time consuming. http://docs.xamarin.com/ios/advanced_topics/binding_objective-c_types


When using MonoTouch you'll still need a Mac with Snow Leopard or better Lion, I believe that Lion will be required in future releases of Apple's iOS SDKs. You are required to install xCode for the Interface Builder as well.

MonoTouch is a cross compiler, so all libraries and development tools are used. The price to deploy and develop with MonoTouch isn't free, I believe the cheapest for personal use is about $499 on top of Apple's fee of $99. That is if you want to deploy to your iPhone or iPad instead of using the Simulator.

A few steps to import native (objective-c) libraries to Monotouch. (The ArcGIS.a library in this case)

Add the native library (.a) to the project just by  right click ->
1. Add -> Add Files, select the library file and add it into the main
directory of your project.

2.      Change the flag to do not build, so MonoDevelop does not try to
build the native library on the solution, the latest MonoDevelop
already does that, however, is a good idea to check.

3.    Create the .NET dll to bind it all.

4.     Now we needed to create a dll to use with MonoDevelop, there are lots
of steps to be able to bind a iPhone native library in MonoTouch, I
was lucky enough that Novell gave me all the support I needed. I
created an interface from the exisiting library, for that I used a
parser provided by Novell to go over the header
files<http://weblogs.asp.net/blogs/albertpascual/MonoTouch/Parser.zip>
The parser can be pointed to a file or a complete directory, and will
create the binding to the Objective-C Type.
"mono parser.exe directory"
or

"mono parser.exe file.h"

5.      Miguel de Icaza has a great documentation of the binding
details.<http://monotouch.net/Documentation/Binding_New_Objective-C_Ty
pes> Please read carefully how to bind each object on the
documentation, so you can fix errors after the parser, is very
important to learn the Objective-C syntax.

6.      Then that created the C# code and enums, I used those to create the
library by using the MonoTouch application bTouch, make sure you run
it on a console window, I fixed the errors produce by the parser so
you can download the C# code files from here, you'll find that there
are 4 files, 2 for the device and 2 for the
simulator<http://weblogs.asp.net/blogs/albertpascual/MonoTouch/ArcGISLibrary4MonoTouch.zip>.
You can find the dll created as well that will bind to the ESRI
libArcGIS.a iPhone SDK. You can always recreate the dll by running btouch.

/Developer/MonoTouch/usr/bin/btouch -v parserArcGISClassesSim.cs
-s:parserArcGISEnumSim.cs

7.      The last step to link everything; you need to change the project
settings as well, all the information is here from
MonoTouch.net<http://wiki.monotouch.net/HowTo/Interop/Consuming_3rd_Pa
rty_ObjC_Libraries> however the linker has a few issues and Geoff
Norton from Novell gave me the perfect flag to avoid the problem, you
must also specify use the -ObjC and -all_load linker flags in your
project's Other Linker Flags build setting.
This is because the ArcGIS library defines objective-c categories
which do not get loaded without these flags, is not a problem on the
-ObjC like we first thought.

8.     -gcc_flags "-L${ProjectDir} -lArcGIS -framework CFNetwork -force_load
${ProjectDir}/libArcGIS.a"

9.      Now you are ready to write some C# code and with a few simple line
of code after adding your Map View using the Interface Viewer.

As you can see the preparation of the project is not trivial, however
afterwards, you'll be able to write code in MonoDevelop ( the
MonoTouch editor )

public override bool FinishedLaunching (UIApplication app,
NSDictionary
options)
{
      // If you have defined a view, add it here:
      // window.AddSubview (navigationController.View);
      MonoTouch.Foundation.NSUrl myurl = new
MonoTouch.Foundation.NSUrl("http://server.arcgisonline.com/ArcGIS/rest/services/ESRI_StreetMap_World_2D/MapServer");
      AGSTiledMapServiceLayer second = new AGSTiledMapServiceLayer(myurl);
      myOutletMap.AddMapLayer(second, "basemap");

      return true;
}


Hope this helps to get you started.

Cheers
Al

View solution in original post

0 Kudos
6 Replies
by Anonymous User
Not applicable
The short answer, it is possible. As Monotouch is a cross compiler and if you want to use C# to write code that becomes a binary, you can do that, yet it takes a little work to set it up. Yet if you are serious to use MonoTouch I would recommend first to create a simple app with a map. There is an old sample you can use to start:

http://www.arcgis.com/home/item.html?id=4d292f8a378b4a3ca67178974d9eeed3

NOTE: This is a proof of concept only!

Yet you'll have to update the ArcGIS.a library to the 2.1 How to do that is here to create the interface for the library: http://wiki.ios.xamarin.com/HowTo/Interop/Consuming_3rd_Party_ObjC_Libraries

The binding of the library can be the most time consuming. http://docs.xamarin.com/ios/advanced_topics/binding_objective-c_types


When using MonoTouch you'll still need a Mac with Snow Leopard or better Lion, I believe that Lion will be required in future releases of Apple's iOS SDKs. You are required to install xCode for the Interface Builder as well.

MonoTouch is a cross compiler, so all libraries and development tools are used. The price to deploy and develop with MonoTouch isn't free, I believe the cheapest for personal use is about $499 on top of Apple's fee of $99. That is if you want to deploy to your iPhone or iPad instead of using the Simulator.

A few steps to import native (objective-c) libraries to Monotouch. (The ArcGIS.a library in this case)

Add the native library (.a) to the project just by  right click ->
1. Add -> Add Files, select the library file and add it into the main
directory of your project.

2.      Change the flag to do not build, so MonoDevelop does not try to
build the native library on the solution, the latest MonoDevelop
already does that, however, is a good idea to check.

3.    Create the .NET dll to bind it all.

4.     Now we needed to create a dll to use with MonoDevelop, there are lots
of steps to be able to bind a iPhone native library in MonoTouch, I
was lucky enough that Novell gave me all the support I needed. I
created an interface from the exisiting library, for that I used a
parser provided by Novell to go over the header
files<http://weblogs.asp.net/blogs/albertpascual/MonoTouch/Parser.zip>
The parser can be pointed to a file or a complete directory, and will
create the binding to the Objective-C Type.
"mono parser.exe directory"
or

"mono parser.exe file.h"

5.      Miguel de Icaza has a great documentation of the binding
details.<http://monotouch.net/Documentation/Binding_New_Objective-C_Ty
pes> Please read carefully how to bind each object on the
documentation, so you can fix errors after the parser, is very
important to learn the Objective-C syntax.

6.      Then that created the C# code and enums, I used those to create the
library by using the MonoTouch application bTouch, make sure you run
it on a console window, I fixed the errors produce by the parser so
you can download the C# code files from here, you'll find that there
are 4 files, 2 for the device and 2 for the
simulator<http://weblogs.asp.net/blogs/albertpascual/MonoTouch/ArcGISLibrary4MonoTouch.zip>.
You can find the dll created as well that will bind to the ESRI
libArcGIS.a iPhone SDK. You can always recreate the dll by running btouch.

/Developer/MonoTouch/usr/bin/btouch -v parserArcGISClassesSim.cs
-s:parserArcGISEnumSim.cs

7.      The last step to link everything; you need to change the project
settings as well, all the information is here from
MonoTouch.net<http://wiki.monotouch.net/HowTo/Interop/Consuming_3rd_Pa
rty_ObjC_Libraries> however the linker has a few issues and Geoff
Norton from Novell gave me the perfect flag to avoid the problem, you
must also specify use the -ObjC and -all_load linker flags in your
project's Other Linker Flags build setting.
This is because the ArcGIS library defines objective-c categories
which do not get loaded without these flags, is not a problem on the
-ObjC like we first thought.

8.     -gcc_flags "-L${ProjectDir} -lArcGIS -framework CFNetwork -force_load
${ProjectDir}/libArcGIS.a"

9.      Now you are ready to write some C# code and with a few simple line
of code after adding your Map View using the Interface Viewer.

As you can see the preparation of the project is not trivial, however
afterwards, you'll be able to write code in MonoDevelop ( the
MonoTouch editor )

public override bool FinishedLaunching (UIApplication app,
NSDictionary
options)
{
      // If you have defined a view, add it here:
      // window.AddSubview (navigationController.View);
      MonoTouch.Foundation.NSUrl myurl = new
MonoTouch.Foundation.NSUrl("http://server.arcgisonline.com/ArcGIS/rest/services/ESRI_StreetMap_World_2D/MapServer");
      AGSTiledMapServiceLayer second = new AGSTiledMapServiceLayer(myurl);
      myOutletMap.AddMapLayer(second, "basemap");

      return true;
}


Hope this helps to get you started.

Cheers
Al
0 Kudos
PaulDavis
New Contributor III
Hi Richard,
I'd be interested in trying to get this to work for the current iOS SDK version if you are... I've tried the parsers, etc... and it's a bit to get you head around, especially since the binding projects have progressed since the proof of concept was done..

Regards Paul
0 Kudos
RichardFisher
New Contributor III
Paul: I am interested, and greatly appreciate your interest.

I am currently evaluating possible cross-platform technologies and where possible using ESRI products within them but currently lack the needed hardware and software upgrade to even try it yet so I would not be much help in the near term.

It would be useful if ESRI could offer a path forward to match the two technologies together so that we
have a cross-platform option in the .NET environment and not have what ever we build break the bindings
every time there is an upgrade.

If I learn more I will post what I learn, and hope others like you do the same.

Thanks Rick
0 Kudos
CharlesComstock
New Contributor
Hi Richard,
I'd be interested in trying to get this to work for the current iOS SDK version if you are... I've tried the parsers, etc... and it's a bit to get you head around, especially since the binding projects have progressed since the proof of concept was done..

Regards Paul


Paul,

I'm curious about your experience with monotouch and the iOS Runtime SDK.  Any luck with the newer versions of the SDK? 

thanks,

Chuck
0 Kudos
PaulDavis
New Contributor III
Paul,

I'm curious about your experience with monotouch and the iOS Runtime SDK.  Any luck with the newer versions of the SDK? 

thanks,

Chuck


Hi Chuck,

I'm still trying to find the time to take another look, and also to see what the new Objective Sharpie can help with.

http://docs.xamarin.com/guides/ios/advanced_topics/binding_objective-c_libraries/objective_sharpie

The plan is to get more ram for the mac so I can have my bootcamp Windows running in a vm and play with visual studio but build on the mac. Once I get that going I'll have more of a chance to play.

Regards Paul
0 Kudos
by Anonymous User
Not applicable
Paul, you should try Xamarin Studio. Works in the Mac and is a better experience than MonoDevelop.
Hope that helps

Cheers
Al
0 Kudos