This is on Windows 7 and happens every day if I don’t start the Xamarin Bonjour service before Visual Studio and opening a Xamarin.iOS project. It’s not that big a deal but something must be switching the Xamarin Bonjour Service from Automatic. I set it to automatic a few times but it gets reset to Manual. Once it’s running it stays running for the rest of the day.

bonjour-initialization-failure


If you get this make sure the Bonjour Service is running. If it’s not, open the services MMC. You can do this from Task Manager but make sure on the Processes tab you click the Show processes from all users button as the service may not start. Then on the services Tab in Task Manager, at the bottom right then when the Services MMC opens scroll to the bottom. If you don’t see Started then right click on the service and click Start.

bonjour-service

Hopefully you should be able to select iPhone 6.1 in the combo box and all will be well. If not see this tip on Visual Studio to Mac Connectivity.

It’s not that difficult but there’s not an awful lot about it. I haven’t tried it with .MP3 files but what I’ve done works with .wav.

First create a project folder containing the sound files. Each file should be set to Content in the property/build Action.

sounds

Then define AvAudioPlayer to play the file. I created three in the class:

public static AVAudioPlayer [] player = new AVAudioPlayer[3];
private static int playIndex {get;set;}
....
       public static void PlaySound(string filename)
        {
            playIndex++;
            if (playIndex == 3)
            {
                playIndex = 0;
            }
            if (player[playIndex] != null)
            {
                player[playIndex].Stop();
            }
            try
            {
                var file = Path.Combine("sounds", filename);
                var Soundurl = NSUrl.FromFilename(file);
                player[playIndex] = AVAudioPlayer.FromUrl(Soundurl);
                var onePlay = player[playIndex];
                onePlay.CurrentTime = onePlay.Duration*2;
                onePlay.NumberOfLoops = 1;
                onePlay.Volume = 1.0f;
                onePlay.FinishedPlaying += DidFinishPlaying;
                onePlay.PrepareToPlay();
                onePlay.Play();
            }
            catch (Exception e)
            {
                LogLine("PlaySound: Error: " + e.Message, true);
            }
        }

        public static void DidFinishPlaying(object sender , AVStatusEventArgs e)
        {
            if (e.Status)
            {
                // your code
            }

        }

The playIndex int variable tracks which is the next AvAudioPlayer to be used. Note that the file must specify the directory used – my files are in sounds. The player[] variables exist at the class level not locally because you don’t want the garbage collector to zap them once it exits the PlaySound method.

The AVAudioPlayer.FinishedPlaying event handler (delegate in Apple’s terms) lets you catch when it finishes playing. The AvStatusEventArgs.Status is a bool indicating if it has finished.

Because in my App, two possibly three sounds could play simultaneously, I used three AvAudioPlayers. Without them, you have to stop the current sound playing.

I’m a software developer in London UK, creating Apps with Xamarin and these are my thoughts based on my day to day experiences developing with it. Need a contractor for Xamarin (offsite) or onsite in London or C#? Contact Me.

(August 2014)
I’m just coming up to complete my first App which uses multi-threading, TCP/IP and runs very responsively on an iPhone 4! It’s for Taxi drivers and uses a propietary packet protocol to talk to a server over a TCP/IP port.

It pops up a dialog saying do you want to update your help and if you view the Output then 447MB later of downloads (on the Mac), it starts updating. But next time you run Visual Studio the same thing happens?

It’s not you, it’s the version of the help is 6.0 even though you are on 6.1 (according to the Xamarin Bug Log).  The quick fix is to download the help manually.  As Xamarin engineer Jose Miguel Torres say in the bug report:

“Open XCOde and go to Xcode menu –> Preferences… Then click on Downloads tab and switch from components to Documentation.There should be the iOS 6.1 DocSet entry and the most probably is that it is not installed. Click on Check and Install button from the Xcode dialog and wait for the iOS 6.1 DocSet to be installed. ”

xcodefix

After that, you should see the Mac Server Log

[2013-09-01 10:22:44.2] Using https://developer.apple.com/rss/com.apple.adc.documentation.AppleiPhone6.1.atom
[2013-09-01 10:22:44.9] API Docs installed version: 44.30.0.0
[2013-09-01 10:22:44.9] API Docs official version: 44.30.0.0
[2013-09-01 10:22:44.9] Command [StatusSdk: CommmandUrl=StatusSdk] finished (9)

No more update requests.

After major upgrades, reinstalls etc, you may find that Visual Studio isn’t connecting to your Mac. Here’s a tip or two to help you.

First check the Bonjour Service. This has to be running. I’ve set it to run by default but it keeps getting reset to manual startup so I have to rightclick start it. I’m not sure why this is. Anyone know why when I change it to automatic startup it reverts to manual next day??bonjourservice

There’s a page of tips about installing and connectivity on Xamarin’s online docs.

If you’ve opened a project and it’s not connected. It’ll look something like this.  The No Devices Attached below is the iOS Toolbar so make sure it’s visible.

visualstudio

 

What I’ve found works well is to close this project and create a new blank one. This fires up the connectivity dialog, so you can see if your Mac is being found and diagnose any problems.

Or you can go to the existing Tools/Options and right at the bottom is Xamarin. Click the Configure button.

tools-options-xamarin

 

 

This isn’t meant to start a flame war. I’m an experienced C# developer (at work plus I wrote the About C,C++ and C# website from 2006-2013) and during those years I tried to learn Objective-C. I knew C, understood the Obj-C memory management (pre ARC), about retaining memory etc and understood the message passing with [].

What I found hard though was seeing the big picture (View Controllers and Views) to structuring Apps as well as learn Obj-C at the same time. So I looked at it then worked my way through some open source games. One thing jumped out- the number of files needed was considerable, just like Java one per class only with Obj-C it was a .m and .h file per class!

Then there was Xcode 3 and Interface Builder. I’d grew up with Delphi and then C# so a GUI that let you hook up code to form objects was intuitive and in Obj-C it was somewhat painful jumping from Xcode to IB and then back.

You still get that with Xamarin if you create Apps with Nibs. So far I’ve done everything in code, walking down the nibless route. Xamarin have a new tool somewhere in alpha that generates C# code so fingers crossed, one of these days it’ll emerge blinking into the sunlight.

I’ve spent several years using Visual Studio: all versions from 2003, 2005, 2008, 2010 and 2012 so it’s a comfy home for me and to be able to step through an iPhone App in the VS debugger is very clever and executes faster than I expected. Between the iPhone and my PC is a network with a Mac Mini that proxies I guess the debug data between phone and PC.

But you don’t get it cheap- Visual Studio support in Xamarin is $999 and they expect you to pay that each year for support. You don’t have to of course but you won’t get the upgrades and with an new iOs version each year…

So out of the blue the offer of paid work to convert a Windows Phone App to iPhone with a down payment that bought Xamarin; that’s why I became a Xamarin developer.