Chapter 11. Talking to Other Applications

WHAT'S IN THIS CHAPTER?

  • Making MonoTouch talk with other applications with the OpenURL method

  • Having your applications integrate with third-party applications

  • Accessing the iPhone Address Book or the iPod music library

  • Integrating with third-party libraries with Objective-C and .NET

This chapter discusses the ways you can use MonoTouch to talk to other applications on the iPhone, both Apple-built applications and those downloaded from the App Store. It also provides helpful ways of accessing the iPhone's Address Book and the iPod music library.

The secret behind interfacing with any application on the device is the OpenUrl method on the current UIApplication, which can be accessed via UIApplication.SharedApplication. This method handles where and what to open when you pass in an NSUrl object for it to parse. When the method is called, the app closes in its normal fashion by calling the WillTerminate method as it closes and carries out the appropriate action based on the URL passed in.

INTEGRATING APPLE APPLICATIONS

This section shows how you can integrate Apple-built applications into your own application.

Opening Up Safari

Opening up Safari is a pretty straightforward place to start. The most likely reason for you to close down your app and open up Safari is because you would like a web site to be displayed. The web site URL is the NSUrl object that you pass into the OpenUrl method:

var url = NSUrl.FromString("http://wrox.com"); UIApplication.SharedApplication.OpenUrl(url); ...

Get Professional iPhone® Programming with MonoTouch and .NET/C# now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.