Archive for November, 2014

Xamarin / make a little debugging tool for MKMapView / maps when you don’t want to spend actual time moving around

When you are making an app with GPS routes and you want to create test data (for unit tests or just testing without moving around), you can use the following code;

In ViewDidLoad or whatever used to initialise the view, put:

  1. var tapRecogniser = new UITapGestureRecognizer(this, new MonoTouch.ObjCRuntime.Selector(“MapTapSelector:));
  3.             map.AddGestureRecognizer (tapRecogniser);

And somewhere in the same class;

  1. [Export(“MapTapSelector:)]
  2.         protected void OnMapTapped(UIGestureRecognizer sender)
  3.         {
  4.             CLLocationCoordinate2D tappedLocationCoord =  map.ConvertPoint(sender.LocationInView(map), map);
  6.             locations.Add (tappedLocationCoord);
  8.             HandleDidUpdateUserLocation (this,
  9.                 new CLLocationsUpdatedEventArgs(
  10.                     new CLLocation []{
  11.                         new CLLocation(tappedLocationCoord.Latitude, tappedLocationCoord.Longitude)
  12.                     }
  13.                 )
  14.             );
  16.         }

In my case

  1. List<CLLocationCoordinate2D> locations

which contains all the already clicked locations so we can draw a nice path from all taps which is the same as  say a run or a walk or a drive. Add some small debugging fields for speed and altitude and you can test most real life situations.

Xamarin / playing background music and pausing for sound / text to speech (tts) playback

In FinishedLaunching, add:

AVAudioSession.SharedInstance().SetCategory (AVAudioSessionCategory.Ambient);

This will make any background music/sounds continue to play when starting your app. 
When playing a sound / tts in the app, use; 

var avsession = AVAudioSession.SharedInstance();
avsession.SetActive (true);
avsession.SetCategory (AVAudioSessionCategory.Playback, AVAudioSessionCategoryOptions.DuckOthers);

This will lower the volume on the background music, now you can play the desired sound, for instance (in my current case it is tts); 

speaker.SpeakUtterance (speechUtterance);

Depending on what you are playing, it has a DidFinish, for instance; 

speaker.DidFinishSpeechUtterance += (object sender, AVSpeechSynthesizerUteranceEventArgs e) => {
avsession.SetActive (false, AVAudioSessionSetActiveOptions.NotifyOthersOnDeactivation);

Which will tell the background music to ‘unduck’. 

Prevent annoying iTunes & Image capture from starting when you plug in your phone

Not sure why anyone would want this to happen, anyway:


– goto system preferences -> users & groups
– goto your user -> Login items
– remove iTunes Helper (I don’t want anything started myself)

Image capture is easy as well however it’s an easy option to overlook; 
– open Image capture 
– click on your device (this is the step most forums / blogs about this miss)
– in the left bottom corner click the arrow and set it to No Application: 

Kivy / mouse cursor not showing up after startup

(on OS X but applies to other OSs) 

After searching, recompiling all libraries, etc for two hours someone on #kivy pointed me to ~/.kivy/config.ini which has a show_cursor = 0/1. In my case it was 0. I never touched it (just freshly installed Kivy) and the default is 1, however, it was 0 and thus my cursor did not show.

Xamarin Pushwoosh C# library for iOS / PushNotificationManager.PushManager is null

The instructions on the Pushwoosh site  shows crudely how to install this library for Xamarin. There are different reasons why this won’t work, but the most annoying results (on iOS 8+) in pushManager being null without any errors or issues.

One reason for that Pushwoosh_APPID is missing from the Into.plist.

The other issue, when null still appears is something I have not figured out. Simply removing all the references from the project and recompiling works sometimes; clean all doesn’t etc. It seems to be a common issue (happens often), but no-one so far produced exact steps to fix it.