Follow me on Twitter at Twitter.com/wbm
FYI, I'm blogging most of my stuff over at More Wally now.
You might want to add my rss feed to your reader at:http://morewally.com/cs/blogs/wallym/rss.aspx
January 2010 - Posts - Wallace B. McClure

Wallace B. McClure

All About Wally McClure - The musings of Wallym on Web, HTML5, Mobile, Xamarin.iOS, Xamarin.Android, and Windows Azure.

News

Visual Studio Magazine Column Personal Blog

.NET

Book Authors

Business

Family

Friends

Georgia Tech Bloggers

Personal

Archives

January 2010 - Posts

The iPhone 20 second rule

If you didn't know it, the iPhone has two twenty second rules that developers need to pay attention to:

  • The iPhone has a startup timer. If an application takes longer than 20 seconds to start up, it is killed by the iPhone OS.
  • The iPhone OS will kill any application that is unresponsive for longer than 20 seconds. To work around this, you will need to perform some type of asynchronous operation.

The lesson learned on this is that asynchronous processing is a good thing to learn and understand.

Want to know more about developing with the iPhone?  Check out my Wrox Blox eBook on developing applications with MonoTouch for the iPhone/iPod touch for .NET/C# developers.

Safari and WebKit Development for iPhone OS 3.0

 book cover

I bought this book a few weeks ago. I've been reading it and trying to absorb the features in the iPhone's version of Safari.   I'm impressed.  This book contains a huge amount of information about Safari on the iPhone.  So, why is this important when you can have apps on the iPhone? Have you tried to get an app onto the iPhone?  Its not an immediate process by any stretch of the imagination.  With a web application, you can deploy applications immediately to the iPhone without having to go through Apple's AppStore process.  Its a great read and is very educational.

UIAlertView - the alert box for the iPhone

There are times when the user needs to be presented with some information or question. MonoTouch has a UIAlertView object. The UIAlertView is instantiated with a set of parameters. On the object instance, the .Show() method is called. For .NET developers, this is similar in concept to the .NET MessageBox. For JavaScript developers, this is similar to the window.alert() and window.confirm() methods. 

                var av = new UIAlertView("Badness happened",

"The scheme '" + prot + "' is not supported on this device.",

                    null,

"Ok thanks", null);

                av.Show(); 

UIAlertView

Want to know more about developing with the iPhone?  Check out my Wrox Blox eBook on developing applications with MonoTouch for the iPhone/iPod touch for .NET/C# developers

Opening another application on the iPhone using NSUrl

The NSUrl class is what allows an application to open other applications within the iPhone OS while passing parameters. The calling sequence is fairly simple. There are two steps to making this call:
1. When the NSUrl class is instantiated, a string representing the URL scheme is called. Note that different applications will have different schemes and use different protocols.
2. The static method UIApplication.SharedApplication.OpenUrl(ns) is called, where ns is the NSUrl class. When the static method is called, if it is not possible to open a URL, a false is returned. If it is possible to open the URL that is passed, the URL is opened and a true is returned.

 Some code to do this looks like:

NSUrl ns = new NSUrl(prot + first + sec.Trim());

if (!UIApplication.SharedApplication.OpenUrl(ns))

            {

                var av = new UIAlertView("Badness happened"

                    , "The scheme '" + prot + "' is not supported on this device.",

                    null, "Ok thanks", null);

                av.Show();

            }

Ok, this all sounds cool, now lets look at the format of the url schemes that you can pass into NSUrl.  For a list of them, check out: 
http://wiki.akosma.com/IPhone_URL_Schemes

Want to know more about developing with the iPhone?  Check out my Wrox Blox eBook on developing applications with MonoTouch for the iPhone/iPod touch for .NET/C# developers.  

UIPicker in the iPhone with MonoTouch

 UIPicker

The UIPicker is visually different than the drop down listbox that most .NET developers are familiar, however, it is designed to perform the same type of function.  It allows users to select from a fixed set of data isntead of typing in data in a text box.  Programming with it is fairly simple.  Inherit from the UIPickerViewModel class and then bind the data.

Here's the class:

using System;

using MonoTouch;

using MonoTouch.UIKit;

using MonoTouch.Foundation;

 

namespace OpenUrl

{

 

 

public class ProtocolData : UIPickerViewModel

{

 

public static string[] protocols = new string[]

{

"http://", "tel:","http://maps.google.com/maps?q=", "sms:",

"mailto:"

};

public string[] protocolNames = new string[]

{

"Web", "Phone Call", "Google Maps", "SMS", "Email"    

};

AppDelegate ad;

public ProtocolData(AppDelegate pad){

ad = pad;

}

public override int GetComponentCount(UIPickerView uipv)

{

return(1);

}

public override int GetRowsInComponent( UIPickerView uipv, int comp)

{

//each component has its own count.

int rows = protocols.Length;

return(rows);

}

public override string GetTitle(UIPickerView uipv, int row, int comp)

{

//each component would get its own title.

string output = protocolNames[row];

return(output);

}

public override void Selected(UIPickerView uipv, int row, int comp)

{

ad.SelectedRow = row;

}

public override float GetComponentWidth(UIPickerView uipv, int comp){

return(300f);

}

public override float GetRowHeight(UIPickerView uipv, int comp){

return(40f); 

}

}

}

And then you bind data doing something like this:

ProtocolData protocolDataSource = new ProtocolData(this);

ProtocolSelection.Model = protocolDataSource;

And there you go, you now have a UIPicker with a list of data.

Want to know more about developing with the iPhone?  Check out my Wrox Blox eBook on developing applications with MonoTouch for the iPhone/iPod touch for .NET/C# developers

The Mono / MonoTouch Soft Debugger

Honestly, I thought that it was really cool when the Novell guys put a soft debugger into Mono/MonoTouch so that it is possible to debug an application running on the iPhone Simulator or on the actual device.  Basically, its a set of code inside of MonoTouch that will talk back to the debugging device.  According to the document, it works in the simulator, an iPhone attached to your macintosh, or over wifi if you are ont eh same network.  Thanks guys!

 monotouch soft debugger

Want to know more about developing with the iPhone?  Check out my Wrox Blox eBook on developing applications with MonoTouch for the iPhone/iPod touch for .NET/C# developers

Putting a Point on a Map in the iPhone

I wrote the following code to put a point on a map on the iPhone.  It works pretty well.  Basically, I draw a map, then I inherit from the MKAnnotation object and create a new constructor, go out to geocoder and get a lat lon to senter the map on, and finally, I put a point in the center of the map.  I've got to thank Craig Dunn for the inspiration of inheriting from the MKAnnotation object.

using System;

using System.Collections.Generic;

using System.Linq;

using MonoTouch.Foundation;

using MonoTouch.UIKit;

using MonoTouch.MapKit;

using MonoTouch.CoreLocation;

 

namespace Json

{

public class Application

{

static void Main (string[] args)

{

UIApplication.Main (args);

}

}

 

// The name AppDelegate is referenced in the MainWindow.xib file.

public partial class AppDelegate : UIApplicationDelegate

{

// This method is invoked when the application has loaded its

// UI and is ready to run

public override bool FinishedLaunching (UIApplication app, NSDictionary options)

{

// If you have defined a view, add it here:

// window.AddSubview (navigationController.View);

window.MakeKeyAndVisible ();

 

MapVw.ZoomEnabled = true;

MapVw.UserInteractionEnabled = true;

MapVw.ScrollEnabled = true;

MapVw.ShowsUserLocation = true;

 

btnMap.TouchDown += BtnMapTouchDown;

 

LocationTF.EditingDidEnd += delegate(object sender, EventArgs e) {

       UITextField utf = sender as UITextField;

       Console.WriteLine("EditingDidEnd is finished.");

       utf.ResignFirstResponder();

};

 

LocationTF.Ended += delegate(object sender, EventArgs e) {

};

 

LocationTF.EditingDidEndOnExit += delegate(object sender, EventArgs

e) {

};

 

return true;

}

 

void BtnMapTouchDown (object sender, EventArgs e)

{

GeoCode gCode = new GeoCode();

string location = LocationTF.Text;

double lat = 0.0, lon = 0.0, radius = 0.0;

Location.ResignFirstResponder();

gCode.GetLatLon(location, ref lat, ref lon, ref radius);

Console.WriteLine("Lat: " + lat.ToString() + " Lon: " + lon.ToString());

MapVw.Region = new MKCoordinateRegion(new CLLocationCoordinate2D(lat, lon),

                                      new MKCoordinateSpan(.5, .5));

MapVw.ZoomEnabled = true;

MapVw.UserInteractionEnabled = true;

MapVw.ScrollEnabled = true;

btnMap.TouchDown += BtnMapTouchDown;

gCode = null;

}

 

// This method is required in iPhoneOS 3.0

public override void OnActivated (UIApplication application)

{

}

   }

}

The  MKAnnotuation object is inherited like this:

using System;

using MonoTouch.UIKit;

using MonoTouch.MapKit;

using MonoTouch.CoreLocation;

namespace Json

{

// concept borrowed from Craig Dunn’s blog.

   public class ObjAnnotation : MKAnnotation {

      

    private CLLocationCoordinate2D _coordinate;

    private string _title, _subtitle;

//getters must be overridden to return necessary data.

    public override CLLocationCoordinate2D Coordinate {

       get { return _coordinate; }

    }

//title and subtitle are readonly, thus no setter.

    public override string Title {

       get { return _title; }

    }

    public override string Subtitle {

       get { return _subtitle; }

    }

    /// <summary>

    /// Need this constructor to set the fields, since the public

    /// interface of this class is all READ-ONLY

    /// <summary>

    public ObjAnnotation (CLLocationCoordinate2D Coordinate,

                             string Title, string SubTitle) : base()

    {

       _coordinate=Coordinate;

       _title=Title;

       _subtitle=SubTitle;

    }

}

 

}

The result is this:

mapping on the iPhone 

Want to know more about developing with the iPhone?  Check out my Wrox Blox eBook on developing applications with MonoTouch for the iPhone/iPod touch for .NET/C# developers.

.NET Talks in 2010

I've worked up the following talks for 2010.

If you are interested, get ahold of me.  Contacting me through this blog, LinkedIn, and Twitter are the best.

iPhone Development for .NET/C# Developers. The iPhone is the smartphone leader in mindshare and the amount of money spent on applications. This lead in money spent on applications is expected to grow over the next several years. Objective-C is the native language for iPhone development. .NET developers, who work in the largest general area of development frameworks, have looked at iPhone developers with a great deal of envy. But with the release of MonoTouch, .NET/C# developers can apply their knowledge to iPhone development. This talk with show .NET developers how they can write applictions that run natively on the iPhone.  In this talk, the attendee will be able to immediately being writing and exploring code on the .NET
Intro to Windows Azure. Windows Azure is Microsoft's entry into the cloud computing marketplace.  We'll look at getting an application up and running with azure, data storage in azure, exposing web services over azure, and finally an overview of a running application in Azure.  Attendees will be able to start writing applications for Windows Azure immediately after attending the session.
Introduction to ASP.NET 4 AJAX Client Templates With the initial release of ASP.NET AJAX, Microsoft released an AJAX solution that allows developers to call from the web browser back to the server and retrieve data. With  ASP.NET 4 Microsoft will provide an improved set of features including an easy and simple way to beind data, use client templates to easy bind data to on the client, provide client side events that can be processed, and an improved set of client side controls.  Attendees will be able to immediately able to use the the features of ASP.NET 4 AJAX in their applications after attending this session. 
Introduction to the ASP.NET AJAX UpdatePanel This session is a deep dive into the ASP.NET AJAX UpdatePanel.  The UpdatePanel provides for a mechanism to add client side Ajax capabilities through a server side control.  We'll look at: Quick Intro to the UpdatePanel. How to debug with it.  The UpdatePanel provides client side Ajax functionality. We'll look at how to debug with it and see that the UpdatePanel allows for the server side debugging functionality that mostdevelopers are used to. Its client side programmability features.  The UpdatePanel provides a client side interface into its features. We'll look at the events provided and how they allow developers to add to their applications to improve the user experience. Error Handling.  By default, errors are generated as JavaScript alerts, we'll look at the options for handling errors so that user's aren't forced into the annoying JavaScript alert popup. The data format that the UpdatePanel uses.  When does AJAX not use XML or JSON for data transfer? When it the UpdatePanel is used.  We'll look at the Update Panel's data transfer format. History with the UpdatePanel. One of the most frustrating things from a user's standpoint is that hitting back on Ajax application takes them out of the application.  We'll look at what a developer must do so that a user hitting back does not exit from the application, but merely goes back to the previous state of the application.
Introduction to ASP.NET AJAX With the introduction of ASP.NET AJAX, Microsoft has release support for AJAX applications using their stack of products. We'll look at:
• What is AJAX.
• The Script Manager and options on adding web services and client side scripts.
• Javascript Intellisense increase developer productivity by providing a set of hints regarding the methods that may be called as well as how to add this functionality to scripts that the developer authorizes themself.
• How to call a Web Service and process the result.
• How to debug.
• The UpdatePanel.
• Integration with ASP.NET Services (Membership, Roles, and Profiles).
Opening a Windows Azure application with Web Services and then consuming these services in Silverlight - This is a two person talk with Wally McClure and David Silverlight. We'll look at opening up a Windows Azure application through a set of web services for third parties to develop clients that interface with your application.  Items discussed include: Windows Azure in general. Why you want to open your application. The mechanics of opening an applications. Some of the choices that I ran into with regards to the web services. Then we will switch and open up a silverlight application that interfaces with this application.  In it, we'll look at the challenges of using web services for a third party within a silverlight application.

My thoughts on MonoTouch as we enter 2010

What a wild and crazy last 6 months its been for my personal development direction.  I've always been excited about mobile development.  Every couple of years, I ask somebody at Wrox about a book on mobile development.  Every time, the response is along the lines of "You are f***ing kidding."  In June/July, Novell, the NetWare guys, announced MonoTouch.  Its a library that allows developers writing in .NET/C# to target the iPhone.  Wow, .NET developers, who are the largest market of developers could target the iPhone, the smartphone that clearly has the most mindshare.  I sent an exploratory email to someone at Wrox about doing a Wrox Blox on MonoTouch.  The response was almost immediate, "Get me a proposal and get started.  The iPhone is H O T."

I rebuilt my Macbook and started working with MonoTouch.  I could tell that the product was very early stage.  I'm not sure if the bigger problem was the beta version of MonoTouch or the alpha version of MonoDevelop.  As expected, things started to settle down, bugs were fixed in the product, stability improved, and things got better.  Around the time of the 1.0.0 version of MonoTouch, someone asked me what I thought.  My response was, "I think MonoTouch has really good promise, but it still feels beta like. I hope it feels more complete by year end."  Well, sure enough, it does.

A good friend of mine and fellow INETA Speaker brought up some really good points about the history of open source software, that open source products were typically a nightmare to configure and get setup correctly.  I remember that statement he made very well.  I didn't disagree with  it at the time.  After having used MonoTouch off and on for the last four months and watch it mature, Novell has produced a product that makes developing for the iPhone fairly easy. 

The interesting thing is that Novell has made developing for the iPhone in .NET/C# on the Mac easier than developing on Windows for WinMo in .NET/C# with Visual Studio.  Seriously, what is wrong with that picture?

Overall, I really feel that MonoTouch is becoming a full featured framework for development. As we enter 2010, I'm really glad to add it to my toolbelt. I'm looking forward to new features that Novell is going to add to MonoTouch.

Be careful what you name a Project or Solution in MonoDevelop

I downloaded and installed MonoDevelop 2.2 on my Windows 7 laptop as well as installing Mono 2.6.  Everything installed correctly.  I decided to create my first ASP.NET web application and see if this will actually work.  I created an ASP.NET Web Project.  I got the following errors;

c:\Projects\MonoDevelop\First MD ASP.NET Web App\First MD ASP.NET Web App\Default.aspx(3,3): Error CS1646: Keyword, identifier, or string expected after verbatim specifier: @ (CS1646) (FirstMDASPNETWebApp)

c:\Projects\MonoDevelop\First MD ASP.NET Web App\First MD ASP.NET Web App\Default.aspx(1,1): Error CS0116: A namespace does not directly contain members such as fields or methods (CS0116) (FirstMDASPNETWebApp)

What is the cause of this error?  I've been trying to figure this out.  Then it hit me.  I created a new project with no spaces and not dots.  This new project worked.  Awesome.

Posted: Jan 02 2010, 10:15 AM by Wallym | with 1 comment(s)
Filed under: ,
More Posts Next page »