Showing posts with label iOS. Show all posts
Showing posts with label iOS. Show all posts

Friday, March 2, 2012

Automated Testing with MonoTouch on an iPad: Revisited

Back in December, I wrote this post about my efforts to set up automated testing on an iPad in MonoTouch. I updated that a couple of weeks ago, noting that there was now a --launchdev option which might make all of that unnecessary, so long as your test app didn't need any data. Unfortunately, mine did. However, as of MonoTouch 5.2.5 (or potentially earlier, but 5.2.5 is when I noticed it), I saw a new command-line option appear for the mtouch program: --argument. It's description? "Launch the app with this command line argument. This must be specified multiple times for multiple arguments." Could this be a way I could ditch the separate launcher app and related AppleScript incantations completely? The short answer is yes. The long answer follows, after the break.

Friday, February 17, 2012

Customizing Appearance of Disabled UIBarButtonItems

Have you ever wanted to change the appearance of a disabled UIBarButtonItem? It seems to be a fairly common issue without many good solutions - at least, until iOS 5.0, anyway. Perhaps you've tried this one:

UIBarButtonItem button = 
    new UIBarButtonItem("Untitled 1", UIBarButtonItemStyle.Plain, null);
button.TintColor = UIColor.White;
button.Enabled = false;

It all works fine, up until you disabled the button, at which point your button becomes a very faded version of whatever you had in there. Normally, that's what you want to have happen, because dimming the button is a good indication to the user that the button cannot be pressed at the current time. However, there may be situations where that isn't true...

For example, I have a toolbar with a document title in the center. It's a UIBarButtonItem, so that it can detect touches, and respond by showing a UITextField that allows the document title to be edited. The document editor has two modes: an edit mode, and a run mode. In run mode, I don't want the title to be edited, so I disable the button. However, I still want it to be nice and visible, like a title should be. I also wanted to avoid the obvious workaround of swapping out my title button for another non-functional button with the same content. It would work, but it would kind of break some of the behind-the-scenes stuff we're doing with our user interaction model, and would require me to maintain the state of two separate buttons with the title. Also, a button that is enabled has a little sparkly animation when it is touched, to let you know that it is touchable and that the system recognized that you touched it. The two-button workaround means I would still have that animation, and gives the user the impression that they can still edit the title, but it's not working right.

So, what did I do? Find out after the break.

Saturday, January 21, 2012

Composing Emails and Sharing Files in MonoTouch

Lately, I had to add the ability to import and export data from a MonoTouch application via email. Thanks to everything you get in the iOS SDK for free, this is actually relatively easy. But you do need to know all the places you need to touch to make this happen. You'll need to:

  • Modify your info.plist to specify the file types your application supports
  • Update your application delegate to override the HandleOpenUrl method
  • Update your view controller to show a mail composer
  • Add code to your view controller to import a file that is passed to it and display it

Many thanks to this this tutorial on email sharing to get me going on this.

Details after the break.

Wednesday, December 14, 2011

Automated Testing with MonoTouch on an iPad

Lately, my work has been focused on a brand new iPad application.  My team consists of around 10 members, and the project, while not containing a single line of code before December 1, will eventually grow to be quite large.  I took it upon myself to ensure that we had a solution for automated testing and continuous integration for the project.  Normally, Apple's tools for automated testing would fit the bill perfectly.  However, we happen to be using MonoDevelop and MonoTouch.  So far, I've enjoyed using these tools greatly.  But there was one issue that made automated testing a huge problem: it is impossible to automatically launch an application on an iPad using any of Xamarin's tools!

Update, 2/17/2012

As of version 5.2.3, Xamarin has added a --launchdev switch to mtouch, allowing you to programmatically launch an application on a device, and potentially making the following steps unnecessary. I am still using them myself, as they give me a way to pass information to my test application on the device, such as the IP address of the build server the device should report back to. But if you don't need that kind of functionality, or have a different method for communicating with your application, --launchdev will certainly make your life easier!