Voice Dictation with WatchKit and Xamarin

Apple Watch has fantastic support for converting speech to text. However, there isn’t any direct API access to the text to speech engine in WatchKit. You can get access to it in your apps though via the Apple provided text input controller.

golf watch text input

You can open a text input controller via WKInterfaceController’s PresentTextInputController method. For example, here’s how I show a list of golf course names to start a new golf round in my app GolfWatch:


PresentTextInputController (courseNameList.ToArray (), WKTextInputMode.Plain,
delegate(NSArray results) {
// ...
}
});

In this case a list of course names is displayed along with a button, which when tapped opens a ui to receive speech input. The results are passed to the completion method specified in the third argument to PresentTextInputController. If you only want speech input, simply pass an empty suggestions array in the first argument and the user will be taken directly to the speech input screen on the device (speech input isn’t supported in the simulator).

Visual Studio Code with Xamarin on a Mac

Microsoft just announced a new cross-platform editor that has many of the features of Visual Studio called Visual Studio Code. I downloaded it on my Mac to try out with a Xamarin.iOS project and see if it works. I was pleased discover it works out of the box (as far as I can tell on a first look).

Visual Studio Code works against files and folders. When you open a folder where a Xamarin.iOS project lives, all the files load fine and features such as links to references and even intellisense on iOS classes work great.

Here’s a class that implements a UIView subclass for example showing intellisense on CALayer:

vscode

You can download Visual Studio Code at: https://code.visualstudio.com/Download

Think Ahead

Since the early days of MonoTouch, when it was just a few of us hanging out in IRC deep into the night, I’ve gravitated towards helping other developers. Initially through my blog and speaking events, and later through my MonoTouch book and training course, I was able to help lots of people get started with this fantastic technology.

Not too long after Xamarin was formed, I joined as their first technical writer. Then I moved into a role as the documentation lead, followed by developer evangelism. Being able to work in these roles at Xamarin was the privilege of my career. Not only did I get to work with a brilliant team, but I was able to help so many developers through my writing, speaking and code. After years writing scientific and engineering software behind the scenes, helping others has been refreshing and has become my passion.

Which leads me to an exciting next step. Today I am excited to announce I have joined up with the team at Think Ahead Software to create the best Xamarin consulting group in the world. I’m thrilled to have the opportunity to continue helping developers succeed with my favorite platform and am looking forward to the many amazing applications we’ll help bring to the world.

I’d love to talk to you about how I can help build your app. You can contact me here.

NGraphics in a Xamarin Sketch

Frank Krueger published a new open source graphics library called NGraphics today. As with everything Frank does it looks pretty awesome. It even has its own editor where you can type in code and live preview the output. So you probably won’t need what I’m about to show you, but I was curious if it would work with Xamarin Sketches (just for kicks).

Sure enough, all I had to do was add LoadAssembly calls to reference NGraphics assemblies in the sketch and add the assemblies to the sketchname.sketchcs.Resources folder alongside the sketchcs file. Then, since Frank includes methods to return native image types, such as NSImage on Mac, I can leverage the sketch visualizers in Xamarin Studio to get a live preview.

Here’s Frank’s sample code to draw a house in a sketch:

ngraphicssketch

Sketches in Xamarin Studio Alpha

A new version of Sketches just landed in the latest Xamarin Studio alpha. Let’s take a look at a couple new things that have been added.

In the previous version, images could be loaded in a sketch given the path on disk. Now, you can add a .Resources folder next to the sketch file, with the naming convention of sketchname.sketchcs.Resources.

For example, with a sketch named Sample.sketchcs, I created a folder named Sample.sketchcs.Resources at the same location as the sketch file, and added a file named hockey.png in the folder. WIth this I can write code like the following in the sketch:

using AppKit;

var image = NSImage.ImageNamed ("hockey");

Then I can visualize the image in the sketch:

sketch resources

Speaking of visualizers, they have been greatly enhanced in the latest version. For example, one of the many visualizers that has been added is for a CIImage. Therefore you can quickly iterate and test the results of different Core Image filters without needing to deploy an app!

For example, here’s some code to apply a noir effect to the above photo:

var noir = new CIPhotoEffectNoir {
    Image = new CIImage(image.CGImage)
};
		
var output = noir.OutputImage;

This result is immediately available to view as shown below:

CIImage visualizer

There are 41 filters in total now, including NSAttributedString, NSBezierPath and CGPath to name a few.

See the Xamarin Studio release notes for the complete list, as well as all the other features that have been added.

CBPeripheralManager for iBeacons in iOS 8

I recently ran into an interesting issue with the code for the FindTheMonkey iBeacon app. Previously I had the code for the app to act as an iBeacon using a CBPeripheralManager, which I created in the ViewDidLoad method. This previously worked fine but someone ran into an issue where ranging for the beacon never discovered it. To resolve this involved a couple small changes:

  1. Move the creation of the CBPeriheralManager into the constructor.
  2. peripheralDelegate = new BTPeripheralDelegate ();
    
    peripheralMgr = new CBPeripheralManager (
      peripheralDelegate, 
      DispatchQueue.DefaultGlobalQueue);
    
  3. Call the StartAdvertising method in ViewDidAppear.
  4. public override void ViewDidAppear (bool animated)
    {
      base.ViewDidAppear (animated);
    
      var power = new NSNumber (-59);
      peripheralData = beaconRegion.GetPeripheralData (power);
      peripheralMgr.StartAdvertising (peripheralData);
    } 
    

With these changes in place, ranging for the beacon discovers it as it had before:

iBeacon FindTheMonkey