Category Archives: Xamarin

You don’t need an MVVM framework to have a view factory and view model navigation in your Xamarin.Forms app

Motivation

Quite often I get asked what MVVM framework I use when creating apps, or I’m presented a list of MVVM helpers/frameworks/toolkits and am supposed to pick my preference. Let me admit that I indeed do have a preference (it is the MvvmLight toolkit) but this does not mean that my choice is the right choice for you, your project or your team. In fact, I think that there’s quite some misconception going on: many think that using a framework is a requirement to build an MVVM based app. That’s not true. Let’s see what the definition of MVVM is over at Wikipedia:

MVVM facilitates a separation of development of the graphical user interface – be it via a markup language or GUI code – from development of the business logic or back-end logic (the data model). […] MVVM is a variation of Martin Fowler’s Presentation Model design pattern.

There isn’t a single reference to a specific framework, in fact it is not even limited to a specific platform. It is all about decoupling your UI from the actual logic – that’s it. The frameworks and toolkits out there can help you reduce the amount of code you have to write. Code that would otherwise be repetitive and they also add nice features like handling view model navigation which is the topic I want to cover in this blog post.

My intention is to show you that you can focus on creating your app instead of spending too much time on finding the “right” framework. Also, you might not need most of what these frameworks give you or you don’t agree on the way things work in them, or whatever the reason may be.

Using OAuth2 with Microsoft OneDrive and Xamarin.Auth

Last week I had an interesting question about Xamarin.Auth, a library that allows Xamarin apps to authenticate users via standard authentication mechanisms (OAuth2), and store user credentials.

You can see how I wrote the word “standard” in bold because as long as some OAuth2 service follows the standards, Xamarin.Auth should support it. So my answer to whether Xamarin.Auth will work with OneDrive’s OAuth mechanisms was clearly “of course, it does”.

I was wrong.

iOS Background Transfer – what about uploads?

Downloading files in the background is easy with iOS since the introduction of the NSUrlSession background transfer APIs. There are plenty of examples and instructions around for ObjectiveC but also for Xamarin.iOS.

Documentation about the APIs is pretty exhaustive over at Apple and covers everything you have to know to get started.

And then, you start asking yourself: what about uploading data? And it turns out there aren’t so many working examples and in fact it can be quite tricky to get things up and running. I was in contact with Apple support and they helped me to find answers to many of my questions. This blog post is trying to conserve to essence of my mail communication as it can help others who are challenged with implementing background upload.

Launching an Android Activity of another APK

We have discussed Android and its Activity system today. It is quite hard to grasp for an iOS guy like me; it feels…special.

I certainly know how to start an activity within my own app and I understand the difference of an explicit Intent vs an implicit one. But there are a couple of questions I couldn’t find answers to, particularly not something that would show how things work with Xamarin.Android.

So I created a small test app to answer the following questions:

  1. How can another app be launched directly?
  2. How can an Activity of another APK be started via an explicit Intent?
  3. How to implicitly start an Activity of another APK?

Xamarin.iOS, the garbage collector and me

A lot has been written about the Garbage Collector and Xamarin.iOS. Lately, I’ve been hit by some surprises and I want to share my findings. Let me say that there is not a single bug involved! All the issues I describe are either documented or show standard behavior of the .NET runtime. The fact that Xamarin.iOS lives on top of a reference counted world makes things a bit more difficult.

Many thanks to Rolf Bjarne Kvinge for his patience, Marek Safar for sharing the secrets of Mono compiler with me, Rodrigo Moya for helping me with the Xamarin Profiler, James Clancey for his drawings about native reference cycles 🙂 and Chris van Wyk for supporting me in these moments of “good god, this cannot be!”

Adding async/await to CocosSharp actions

UPDATE: The CocosSharp team has decided to integrate my ideas directly into their source! 🙂

Are you a C# programmer? Using Xamarin? Are you interested in making great games that run…

  • cross platform,
  • from one code base
  • and are powered by Cocos2D and XNA?

If yes, then you should check out CocosSharp!

I used Cocos2D in the past (the “good” old days of ObjectiveC…) and liked it a lot. Seeing all this translated to C# just freaks me out! 🙂

However there has been one thing that bugged me: chaining actions and running actions simultaneously.

Say, you want your character to scale, then increase some score counter, afterwards make the character jump and then reset the animation phase to the default frame. You would use something like:

[code]
var scale = new CCScaleBy (1f, 1.5f);
var jump = new CCJumpBy (1f, new CCPoint (100, 100), 50, 2);

this.RunActions (scale, new CCCallFunc (() => this.UpdateScore ()), jump, new CCCallFunc(() => this.SpriteFrame = this.defaultFrame));[/code]

Works, but with the power of C# we can do better!

Migrating from Parallels Desktop 10 to VMware Fusion 7: Android SDK broken, WP Emulator not working

Recently I switched my Parallels Desktop 10 VM setup to VMware’s Fusion 7. I had various (random) problems with Parallels Desktop 10 and decided to give Fusion a try. The result: Fusion 7 does not support all the fancy DirectX 10 support, but for a virtual Windows 8.1 development machine on my Mac, it is the better choice.

Migrating over was easy: I simply imported the PD10 virtual hard disk. In 30 minutes it was converted over into Fusion’s format and started up just fine. Everything worked pretty well but then I found a view things I had to adjust.

My iOS8 adventure as a Xamarin developer

With this post I sum up my experiences with iOS8 as a developer. If possible I will provide solutions and workarounds.

The release of iOS8 is really unfortunate for me. A lot of my demos have stopped working and it seems like there are some really annoying bugs in iOS8.

Update: Added working example for reachability

Update: Apple confirms bug in iOS8 Simulator regarding backgrounding.

Update: explanation for the NSUrlSession issue found!

iOS8 is draining your iPhone’s battery? Maybe here’s why.

If you like me are an early adoptor of iOS8 – be it because you’re just or curious about the new feature, or did it for work – you might have noticed that your device’s battery life might have decreased a lot. Yesterday I talked to some developer-friends and they told me: “You know what’s cool, iOS8 keeps on running threads even if applications have been backgrounded!” I was baffled.

UPDATE: This post has been moved and is now part of http://krumelur.me/2014/09/23/my-ios8-advent…arin-developer/ ‎

Android – handling screen rotation and different layouts using Fragments with Xamarin

When I was asked if I could demo how to handle different screen sizes and rotation in Android, I created a small project which I’d like to share here. You can find the complete repo at Github.

The demo uses Xamarin.Android and was built using the Compatibility Lib v4 to support Android’s navigation drawer layout. Fragments are used directly and not via the compatibility packages.

Navigation Drawer on a Nexus 7

Navigation Drawer on a Nexus 7