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
Opening another application on the iPhone using NSUrl - Wallace B. McClure

Wallace B. McClure

All About Wally McClure - The musings of Wallym on Web, HTML5, Mobile, MonoTouch for iPhone, MonoDroid for Android, and Windows Azure.

News

Personal Blog

Work Blog

.NET

Book Authors

Business

Family

Friends

Georgia Tech Bloggers

Personal

Archives

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.  

Comments

No Comments

Leave a Comment

(required) 

(required) 

(optional)

(required)