Ceci n’est pas une app

ceci-nest-pas-une-app-mid
Standard

LevelUpMobile_logoRGBCall to action: join us at LevelUp Mobile on September 22nd in Leusden for a FREE inspirational evening on the future of Mobility and Devices.

 

The mobile platform war has been raging for almost ten years now. For now, it seems that Google (Android) and Apple (iOS) have won. (link) Microsoft, though still pushing Windows 10 for mobile as well, has accepted this and started providing high quality mobile apps for both Android and iOS.

Apple and Google have invested a lot in making their platforms richer and richer to attract and retain users. Apple’s advantage of 100% vertical integration of software and hardware has allowed them to create experiences like Apple Pay, 3D-Touch and Touch-ID that are very appealing to users and developers alike. At the same time, both Apple and Google have been putting features into the OS and stock apps that are competing with 3rd party offerings in the App Store. Furthermore, users have come to expect the same experience they get from their OS from 3rd party apps. Though some platform features might seem alike between iOS, Android and Windows, the way they are implemented can vastly differ and require access to core platform API’s.

As a strong proponent of Xamarin, I’ve been working in the world of cross platform mobile app development for almost 6 years now. The reason we chose to go with Xamarin was – first of all – of course the ability to share code amongst platforms, but – equally important – full access to the native platform API’s and the ability to create 100% native experiences. Given the trend of ever innovating mobile platforms, this puts us at a huge advantage over cross platform solutions that go for the lowest common denominator, both in UI (the same UI across all platforms) and UX (most of the time just the common superficial feature set across platforms).

With iOS 10, Apple is showing us a trend where apps can be integrated even deeper in the core OS experience. Of course we already had widgets in Android, but what to think about interactive widgets in iOS’s Today view, enriched with Siri’s AI capabilities? Interactive notifications are becoming more popular. Where a notification used to be a way to alert the user and allow them to open the accompanying app by tapping on it, notifications are becoming a User Interface by themselves, allowing the user to deal with the app’s functionality right from the lock screen.

ios-10-interactive-notifications

Deal with a notification right away from the Home screen. No need to open the app!

The boundaries of apps are blurring even more with advanced features like 3D-touch on the Home screen, and the ability to interact with apps from the Siri screen:

iOS-10-Control-Center-3D-Touch-iPhone-screenshot-001

Direct access to an app’s features through 3D-Touch. No need to open the app!


open_app_in_siri

Siri knows how to invoke your app and show it as a widget right inside its own interface. No need to open the app!


apps_in_imessage

iMessage can invoke your app right from its own interface. No need to open your app!

These are all iOS examples, by the way, but similar features can be found in Android and Windows 10, with its Live Tiles, Cortana integration, etcetera.

In general, user interaction with their mobile devices is becoming more and more streamlined, and to stay ahead as developers, we need to start thinking about these micro-interactions, these Mobile Moments, and offer the most efficient experience with our apps.

Mobile is not a neutral platform (link). The philosophy of web applications (built for browsers, available everywhere, with a consistent user experience everywhere) doesn’t apply here. We don’t build for the web, we build for the OS. Yay for native development!🙂

spoon-boy

There is no spoon.

If we follow this train of thought, it leads us to an existential question: is there actually an app?

I would argue: not anymore – at least not in the traditional sense where we have an icon sitting on the home screen that launches into an application that comes into the foreground and occupies the whole screen. It seems like the days of the mobile “app” are numbered and we have to start thinking about apps as a set of autonomous micro-interactions that work together with the OS and/or other apps.

Luckily for us, as developers, there are plenty of new API’s and frameworks that help us build these interactions and I think it will only become more exciting from a technical perspective to build mobile experiences.

LevelUpMobile_logoRGB

On September 22nd, I’m joining Brechtje de Leij (mobile strategist and expert), Jorn de Vries of Flitsmeister fame, Johan Gorter & Rick Hoving from AFAS Software and the ever brilliant Laurent Bugnion to speak at a one-off inspiring event about the future of Mobile and Devices: LevelUp Mobile. Together with my colleague Geert, our talk is going to be about the exact topic of this blogpost and we’ll show some real life examples of how to implement these Mobile Moments using Xamarin.

If you have not registered yet, you can do it here: http://www.levelupmobile.nl! It’s free and it’s going to be fun!

To get more inspired, read Laurent’s teaser blog post about his upcoming talk: A world of devices.

Xamarin Evolve 16 – Conference Day 2

apple-i
Standard

If you want to read the first 3 instalments, go here:

  1. Training Day 1
  2. Training Day 2
  3. Conference Day 1

This blogpost marks the end of Xamarin Evolve 2016 already. Wow, time flies, but this was another great Evolve. I didn’t expect that the same vibe of Evolve 2013 could be recreated but Xamarin has some special fairy dust and made it happen again, only bigger. Much bigger.

Today was a bit of a roller coaster ride for me – and I wasn’t even at the Wizarding World of Harry Potter anymore! But more on that later…

I attended the Xamarin MVP breakfast at 7:00am, bright and early. A nice bunch of people from the MVP community showed up and we got to chat with some of the Xamarin folks about the Microsoft acquisition and the way forward.

Keynote

The main Evolve event continued with the Day 2 Keynote session with special guest Grant Imahara from Mythbusters. Grant had an inspirational story about his time as a Mythbusters team member, doing all these crazy things for the sake of science (and fun). The way he had to solve problems and challenges has parallels with how we approach software development. It comes down to fostering creativity and using failure as a design tool.

Innovation starts with Creativity. LEGO is a great tool for kids to boost creativity. #XamarinEvolve @grantimahara

A photo posted by Roy Cornelissen (@roycornelissen) on

Sessions like these always work great for inspiration.

Breakout sessions

Designing for TouchJosh Clark
I planned on attending the 2 hour ‘Designing for Touch’ seminar by Josh Clark. Josh is an engaging speaker and his presentation covered a lot of great tips about how people hold and operate their mobile devices using Touch.

Depending on the size of the phone, there are roughly three different types of grips: one-handed, cradled grip + 1 finger, the so called “BlackBerry prayer” grip. As it turns out, the thumb is the most important input “device” a user has, so it makes sense to optimize for input and/or manipulation via thumbs.

The preferred placement of controls on Android differs from iOS. Android has a fixed “soft button” navigation bar at the bottom of the screen, and putting controls just above that bar is tricky. On iOS it makes sense to put tab-navigation at the very bottom of the screen. Per platform native UI’s have very specific needs, so if you want to build a quality app, you must keep this in mind.

FullSizeRender 15

Josh put his slides up for download. They’re worth checking out:

Unfortunately I had to leave the second part – just when Josh started to talk about gestures – because I had a special invite for…

Lunch with Woz?!

Wow! I was privileged to join a party of Xamarins and customers in a small lunch setting together with Apple co-founder and inventor of the Apple I and II computers, Steve Wozniak! It was mind blowing to meet and greet such an icon of our industry.

I guess it was overwhelming to most of us because we sat there most of the time just marvelling at his amazing stories. Woz told us that he doesn’t eat lunch, he sticks with just one meal per day, which gave him plenty of room to talk. It was great to hear about his first endeavours in making computer hardware, soldering the circuits for arcade games, his favourite apps and the Apple Watch.

FullSizeRender 19.jpg

Three industry legends!

What struck me most was that he has a sincere passion for software development and software developers. He is definitely a tech geek for life and a genuinely nice guy. I got my picture taken with Woz, but I’m still awaiting the pic from the photographer… Exciting!

Xammy and Closing keynote

Xammy AwardsStephanie Schatz
At the end of the day, it was time for the Xammy Awards, an award for outstanding apps built with Xamarin technology. The finalists are listed on the Xamarin Blog. One of them, in the Enterprise App category, was NS / Dutch Railways.

Marco and Patrick from Info Support are members in the team building this app. I worked at Info Support for 16 years and my last project before I left the company for Xpirit was: this very project! I was the solution architect during the startup and first iterations of development of this app and the team did a fantastic job building these apps on top of that architecture. So I was pretty proud when this happened:

Congratulations Marco and team, great job!

Closing panel discussionSteve Wozniak & Miguel de Icaza
Steve Wozniak and Miguel de Icaza joined on stage for a panel discussion about the history and future of apps. The same way as during lunch, Woz passionately told his fantastic stories and shared his vision on where computing might go in the future. Woz believes strongly in personal assistants like Siri and/or Amazon Echo.

FullSizeRender 18

Unfortunately we didn’t get to hear much from Miguel in this session, but Woz was an inspiration. Another thing that stood out was his dedication to educating young children to do programming. In his heart, Woz always stayed an engineer and a teacher.

Closing thoughts

We ended the conference at a closing party over at the Dragonfly restaurant. This was another great location with fantastic Japanese food.

Closing thoughts: Evolve 2016 was a fantastic conference. I’m amazed how Xamarin managed to keep the vibe of the original Evolve in 2013, and just made it bigger and more awesome. All Xamarins were very approachable and close to their community members. I found this in my bedroom after the keynote, for participating in the DevOps panel yesterday:

FullSizeRender 16

It says: Thank You! From Xamarin. I say: Thank YOU, Xamarin! See you next year at Evolve 2017. Let’s make this happen!

FullSizeRender 17

The band of brothers with whom I spent this week.

Still here? What’s that? Food posts? Ok, here are some…

  • IMG_1087FullSizeRender 21FullSizeRender 22

Time for the Future of Apps!

 

Xamarin Evolve 16 – Conference Day 1

FullSizeRender 10
Standard

Day 1 of the Xamarin Evolve 2016 conference is a wrap! It was a full day for me… It started at 6:15am for the Mini-Hack 5k run, organised by Craig Dunn. A bunch of Evolve attendees went for a leisurely run in the area, thereby unlocking the first Evolve Mini-Hack.

Keynote

After a refreshing shower and some breakfast, it was finally time for the keynote. The one impression I had after this keynote is: Xamarin is on fire! The keynote was huge. A big stage, an enormous screen and 1700+ excited people in the room anticipating what Xamarin would be announcing.

I made a sketch note out of my personal highlights:

FullSizeRender 10

A lot of topics were covered. I want to share the ones that stood out to me:

open.xamarin.com
The Xamarin team has been working hard to release the Xamarin platform and its surrounding frameworks as Open Source Software on Github. This morning it was released to the public. You can find it via open.xamarin.com, or directly on GitHub. This must be a breakthrough moment for Miguel! Congratulations to the whole team for this achievement, and thank you for being such strong believers in OSS.

FullSizeRender 11

It made sense that Xamarin was closed source when it was their bread & butter. But now at Microsoft, with their fresh new attitude towards open source, it’s great to see Xamarin added to that array of OSS products and frameworks.

FullSizeRender 13

Xamarin Studio 6 Release Candidate
The Release Candidate for the latest version of Xamarin Studio is available now in the Beta channel. This is a very nice release, which features a Dark Theme, a complete visual overhaul to fit with the UX guidelines for OS X El Capitan and built-in Roslyn support. I’ve been working with the preview version on and off and it has matured a lot. I really like the new polished look and the more stable code editor thanks to Roslyn. One of the most notable changes is the Broken State Support, so that IntelliSense doesn’t blow up if there’s a syntax error a few lines above.

iOS Simulator for Windows
The new iOS Simulator was already presented briefly in the //build/ keynote by Miguel. However today Miguel showed how pen pressure input on a Surface Pro running the simulator is passed through to the iOS Simulator which runs on a Mac somewhere in the network.

Xamarin.Forms
The cross platform UI framework, Xamarin.Forms, is becoming more and more mature. This update brings support for so-called DataPages: a ready built and styled set of views that you can feed Azure Mobile Services data or local storage of JSON data. This is a higher level abstraction that lets you set up data driven pages very quickly, but I’m not sure how suited this is for production scenario’s. There is no MVVM in play – at least not for the developer, maybe behind the scenes – to tweak the behaviour. And you know me when it comes to abstractions…🙂

A feature I did like *a lot* is the ability to drop in a native UI control directly into a Forms layout hierarchy. It’s called Xamarin.Forms Native Embedding. So you can now add a native Floating Action Button to your Android app without the hassle of writing a Renderer, etc.

And then…

The Xamarin Forms Previewer is a built in player for your Xamarin.Forms markup code that gives you Gorilla Player like direct feedback inside Xamarin Studio while you’re editing your pages. This is so awesome, because it speeds up the development cycle tremendously! Definitely one of my favourite announcements from the keynote and Nina Vyedin did a great job presenting it.

Xamarin Workbooks
Miguel already talked about Xamarin Workbooks at //build/ and he showed us how the tool is progressing. Workbooks is a fantastic tool for teaching and communicating about code. My pal Marco already alluded to this in his blog: it’s a nice visual way to teach children to code for example. I’ve been doing some classes for the Dutch “hour of code” initiative called CodeUur.nl and I’m thinking about using Workbooks as a tool for that. In any case, it’s clear from the keynote that Workbooks is Miguel’s favourite project at the moment. And rightfully so.

HockeyApp, Insights and Test Cloud Live!
After the Microsoft acquisition, the mobile DevOps toolset at Microsoft is pretty complete. As became clear in the Keynote, Xamarin Insights will merge into HockeyApp to become a compelling tool for deploying and monitoring apps. Donovan Brown from Microsoft came on to rub some DevOps on all of this and walked us through those tools.

The keynote ended with a sweet “one more thing” moment: the announcement of Test Cloud Live. Wow! Ever had your app crash on some obscure device and had a hard time tracking down that bug? Well, now you can attach your debugger to that device in the Xamarin Test Cloud and start debugging your app! Mind blown!

giphy

Bear in mind that you’re debugging over a network connection to a device that sits in the Xamarin Test Cloud device center in Denmark, and the technology is early preview, but this is so promising!

I was amazed by all the announcements, especially how fast Xamarin was able to open source all of their stuff and release the new goodies.

Breakout sessions

For the breakout sessions, I mainly looked for sessions that were not so much technical, but more inspirational to get some nice new ideas.

Contextual CommunicationBrent Schooley
Brent is from Twilio, who are experts in communication technology, but he did a great job not making this talk about Twilio. Instead, I found this an inspiring talk about improving and modernising business communication.

FullSizeRender 7

The main 4 tenets he highlighted are that communications should be:

  • Contextual: what do you already know about the user/customer? Context matters to make communication more personal and …
  • Streamlined: if you can leverage context, you can get down to the point quickly and make conversations as short as possible
  • Secure: again, if you leverage context and what you already know about a user, you don’t have to communicate that information again every time. This saves you from exposing security or privacy sensitive information.
  • Medium of Choice: the customer must be able to choose his/her medium of choice. So an app cannot be the only option. Some people prefer to call or use chat.

Brent demonstrated this with an inspiring demo-app where he started a call from inside a fictitious airline app, and had information (context) exchanged automatically into the app during the conversation to get through a transaction in a streamlined manner. He then used TouchID to verify the customer’s identity to finalize the transaction (secure).

He also covered the new “Bots” trend. With Microsoft’s new Bot Framework and Cognitive Services, we can build interesting things to make these conversations as contextual, streamlined and secure as possible and reuse that across different media. It remains to be seen if 2016 will indeed be the year of the Bot.

I really enjoyed Brent’s talk; he definitely made me think about interesting use cases to improve communications by looking beyond “an app for one single process”. This is what I will focus on at Xpirit for our Mobile strategy.

Clicking on the Real World with iBeacon – Jim Bob Bennett
Similar to the previous session, this session also worked as an inspirator for me to look beyond that one app on the device that your user interacts with. iBeacons are a great way to make the physical world your interface. For example: as I walk into a Starbucks, using iBeacon, they can recognise that I’m entering the shop and know which coffee they have to make so I can walk right up to the counter and pick up my double espresso and pay with my credit card linked to my Starbucks account. Cool. Jim Bob showed how to do this with the iOS CoreLocation API’s.

Unfortunately I had to leave the iBeacon session early, to be in time for my DevOps discussion panel at the Mobile Leaders Summit.

The Future of Connected Devices with Philips hue – Eric Shapiro, Sait Izmit, Mike James
To be honest, I was a bit disappointed with this session, as it was mainly a product placement session for Philips hue, driven by videos instead of much substance. The interesting part for me was Mike’s part in this case, where he showed how to develop against the hue bulb using the Q42.HueApi SDK.

FullSizeRender 6

Adventures in PerformanceMark Probst
This session was a deep dive on the way Xamarin does their performance benchmarking. It was a little bit different than I had expected, but interesting and entertaining nonetheless. I really appreciated Xamarin’s transparency: Mark spoke about some of the challenges they had in the Garbage Collector and the experimental ways they are trying to improve performance and bringing down GC pauses. Really some clever stuff!

FullSizeRender 14.jpg

No big lessons here, except appreciation of Xamarin’s transparency and respect for the smart guys working on the Mono runtime.

Xamarin Party!

In the evening, we celebrated Xamarin Evolve 16 at the Wizarding World of Harry Potter theme park. We took all the rides, including the crazy intense roller coaster and the big splash over in Jurassic Park. The food and the vibe were awesome!

I didn’t get to take many pictures, but there’s a lot of that going around on the #XamarinEvolve Twitter feed.

I’ll leave you with some inevitable food pics and some from the party🙂

Dumplings #food #xamarinevolve

A photo posted by Roy Cornelissen (@roycornelissen) on

Golden Snitch popsicles #food #xamarinevolve

A photo posted by Roy Cornelissen (@roycornelissen) on

Jurassic Park! #XamarinEvolve

A photo posted by Roy Cornelissen (@roycornelissen) on

T-Rex #xamarinevolve

A photo posted by Roy Cornelissen (@roycornelissen) on

Xamarin Evolve 16 – Training Day 2

FullSizeRender 3
Standard

Time flies! The second day of training at Xamarin Evolve is over already and I just came back from the awesome opening party in the Darwin Lounge.

The main conference starts tomorrow. I’m honored to be on stage with some industry giants at the Evolve Mobile Leaders Summit track in a panel discussion about The Unique Challenges of Mobile DevOps. But that’s tomorrow!

About today: before the training, the day started at 6:15am (!) with a 5k test run with for the first Mini-Hack tomorrow morning. I spot an orange Xpirit T-shirt🙂

The training part was another intense day from 9am-6pm, but it was a good day. I’d say the content of today was a bit better and deeper than what we learned yesterday, at least for me personally. We covered three major topics:

Securing local data
This part was all about dealing with data locally on the device, especially sensitive data in terms of privacy and security. We had a look at what the Xamarin.Auth component has to offer for local storage of sensitive data. This component (you can find it on GitHub and on Nuget) uses the platform specific facilities for storing data in a secure container, i.e. the KeyChain on iOS and a secure KeyStore inside the app’s sandbox on Android.

Be sure to get the latest 1.3.0 version of the Xamarin.Auth component though, as this is a bait-and-switch PCL library that also offers support for the Windows platform, whereas the older 1.2.x version doesn’t.

warning-stamp.png

There’s one caveat with the Xamarin.Auth component though… The KeyStore file on Android is locked with a hard coded password. The Android app in one of my previous projects was actually flagged in a security audit because they extracted the Xamarin.Auth DLL, decompiled it and found the hard coded key. Pretty iffy, because this means that the KeyStore data in every app that uses this library can be easily opened and read by extracting the file from the sandbox and using the key that’s publicly available on GitHub!

I made a pull request about 2 years ago that fixes this problem, at least in a way that you can provide your own key. But somehow Xamarin didn’t get around to merge it yet, so the vulnerability was still there, also in the 1.3.x version. The funny thing was that as we were doing the training, one of the Xamarin developers was actively working on this component. We pulled him into the training, explained the problem and he immediately went to work to see if he could merge my fix. How awesome!

FullSizeRender 4.jpg

How awesome is this: Xamarin Developer DNA… everyone could add their own string, picking the pegs that fit with their preference. The result is this awesome, unique “Xamarin DNA” sequence. A work of art!

The other part of this chapter was about the awesome PCL.Crypto component. This component is also a bait-and-switch PCL library, which means that the PCL portion contains nothing more than the API definitions for your shared code to compile against (the bait), but uses the actual device specific implementation at runtime (the switch). This means that PCL.Crypto can use the platform specific crypto API’s developed by Google, Apple and Microsoft themselves instead of relying on its own security implementation. Much the same as the Xamarin.Auth component solves its local storage issues. For developers familiar with the WinRT crypt API’s for example, there is a special WinRTCrypto API that you can program against, but PCL.Crypto will map this to the underlying native API’s. Pretty clever. For example: a method for encrypting some data could look like this:

public static byte[] Encrypt (byte[] plainText, byte[] keyMaterial)
{
  var provider = WinRTCrypto.SymmetricKeyAlgorithmProvider
    .OpenAlgorithm(SymmetricAlgorithm.AesCbcPkcs7);

  var key = provider.CreateSymmetricKey(keyMaterial);
  var IV = WinRTCrypto.CryptographicBuffer.GenerateRandom(16);
  var cipher = WinRTCrypto.CryptographicEngine.Encrypt(key, plainText, IV);

  var cipherText = new byte[IV.Length + cipher.Length];
  IV.CopyTo(cipherText, 0);
  cipher.CopyTo(cipherText, IV.Length);

  return cipherText;
}

PCL.Crypto can be used quite easily in combination with Xamarin.Auth to encrypt or hash data before storing it. At least as long as your app is using the not-so-secure version of Xamarin.Auth – with the hard coded key – using something like PCL.Crypto to secure the values that go into the secure storage is a real necessity! But it’s good practice to do it anyway.

OAuth
Next we went into OAuth for authorizing access to an API from a mobile app. OAuth in itself is a pretty broad topic and enough to fill tens of blogposts. One of the important points here is that for mobile apps, basically there are only two OAuth flows that are really usable:

Screen Shot 2016-04-26 at 22.50.26

The Implicit flow or the Authorization Code flow. The other flows aren’t really suitable for mobile apps (or browser apps involving JavaScript code), since this means that there will be client secrets hidden inside the app, and they involve dealing with a user’s password in the app itself instead of handing that off to an Identity Provider. The Client Credentials flow is typically used for service-to-service communication, usually on behalf of the user.

Xamarin.Auth provides some nice API’s to easily initiate a login sequence, using a web view that follows all the redirects that are part of the OAuth flow, to obtain an access token (or authorization code).

Memory Management Issues
The most interesting part of today was about diagnosing and dealing with Memory Management Issues. I actually learned a lot about how both the Xamarin.iOS and Xamarin.Android frameworks work in terms of memory allocation. It’s important to understand that in both cases, you are always dealing with native objects, managed peers and a binding layer in between, provided by Xamarin. At least, for those objects that are actual native platform classes.

Under the hood, there are some intricacies to be aware of. For example: in order for iOS’s reference counting mechanism to work, you have to be very careful to release references to native objects, for example by making sure to always unsubscribe from event handlers. For Android, it’s important to realise that you’re working with two Garbage Collectors: the Mono one and the one in the Android Java VM. There are a lot of details, but there is some nice guidance up on the Xamarin Developer site about this [iOS] [Android].

You can prevent a lot of memory issues by following a couple of important guidelines. Also the Xamarin Profiler is a great tool for diagnosing possible memory leaks.

Lots of excitement for the opening of the Darwin Lounge at #XamarinEvolve

A photo posted by Roy Cornelissen (@roycornelissen) on

 

Darwin Lounge
As for the (other) fun part of Evolve: the Darwin Lounge was opened this evening, accompanied by a huge buffet and a nice range of tasting stands for artisanal chocolate, local beers and hipster coffee🙂 This tweet sums up how I felt this evening:

It’s no secret that I’m an avid foodie, so suffice to say that I was in seventh heaven when it comes to the food that was served here. This means that you have to sit through my Instagram food porn pictures now:

Excellent chocolate. The Phillipines one is a clear winner #food #XamarinEvolve

A photo posted by Roy Cornelissen (@roycornelissen) on

 

I expected to visit a mobile dev conference but instead I've come into food discovery heaven. #XamarinEvolve #coffee

A photo posted by Roy Cornelissen (@roycornelissen) on

 

Great hipster pour-over coffee at #XamarinEvolve

A photo posted by Roy Cornelissen (@roycornelissen) on

 

Hmm, macarons #XamarinEvolve #food

A photo posted by Roy Cornelissen (@roycornelissen) on

 

Beer tasting at #XamarinEvolve. Local beer from Orlando Brewery. Good stuff.

A photo posted by Roy Cornelissen (@roycornelissen) on

 

 

So… Xamarin sure knows how to throw a party🙂 Of course, the Darwin Lounge at Evolve is mainly about cool geek stuff and tech inspiration. There’s lots of that going on as well. Lots of IoT stuff, drones flying around, etcetera. Check out the Twitter timeline for #XamarinEvolve for a great impression of the fun things out there.

IMG_0946

Great buzz and lots of hacking going on in the Darwin Lounge

IMG_0944

These robot spiders are pretty creepy!

IMG_0943

LEGO Mindstorms, totally cool! Their official iPad app for programming the Mindstorms robot was built with Xamarin

Be sure to tune into the Evolve keynote tomorrow at 9am EST. Rumours are that it’ll be spectacular!😉

Xamarin Evolve 16 – Training day 1

orlando-panoroma
Standard

Hi there from Orlando, FL! Yesterday was the first day of the Xamarin Evolve 16 pre-conference training. And man, we’re already having a blast here. Evolve 16 is even bigger than the previous one, and on the pre-conf training alone, there are more people than there were at the original, legendary Evolve 2013; in total! Impressive.

Finally it's happening! #XamarinEvolve

A photo posted by Roy Cornelissen (@roycornelissen) on

My mobile peer at Xpirit, Geert and I arrived on Saturday, together with a bunch of fellow Dutchies including some of my former colleagues from Info Support. It’s nice to catch up and hang out.

In the training, we’re doing the Intermediate track, which offers some more advanced topics. I have to say that most of the topics are already familiar, but for us this is also a great opportunity to get to know the Xamarin University material. We’re working towards certifying ourselves for delivering the official Xamarin University training curriculum at Xpirit to be the first Dutch Xamarin Training Partner! How awesome is that? Stay tuned for more news!

The main topics we covered were:

Asynchronous programming with async/await
For this module we dove into the mechanics behind the Task Parallel Library in .NET and the async/await keywords. This stuff is so important to get right as it’s crucial for quality apps to make sure that you’re not wasting the main UI thread by doing expensive work like heavy CPU-bound work or (network) I/O. The course went into some of the mechanics of async/await – with the compiler generated state machine that ends up in the generated IL.

The problem with async/await is that the syntactic sugar makes it almost too easy to make work inside your app asynchronous. The point is that making things asynchronous isn’t always necessary and using async/await the wrong way may actually hurt the app in the sense of complexity and possibly performance more than it helps. Understanding the state machine that the compiler generates, the effects of ConfigureAwait(false), working with the Dispatcher, etcetera is crucial if you want your apps to be responsive.

Patterns for reuse
A topic that’s dear to my heart. Marcel and I actually did a pretty popular talk about it at Evolve 2013. IMO, this stuff all still holds true, however we have progressed a bit when it comes to the maturity of the Xamarin platform. With the advent of Xamarin.Forms, more and more code sharing techniques are possible and go right up to the top UI level. On the other hand, Xamarin.Forms already takes away a lot of the hard work of bridging platforms. Very nice, but – my pet peeve – beware of the abstractions!🙂

It all comes down to keeping things as simple as possible. In the training, we talked through using the Factory and Service Locator patterns, but our common conclusion was that they involve a fair amount of Yak Shaving.

front

In the end, Dependency Injection is a relatively clean way of dealing with dependencies that have per platform implementations. In my experience, using a light weight DI container like SimpleIoC is sufficient for most apps. Let’s be honest, in an average app, you don’t really need much sophisticated lifetime management or other things. You just want to be able to swap in per platform implementations of some components to use them from shared code. But before you start building your own components, head over to Xamarin’s plugin repo on GitHub because a lot of plugins are already available. And they generally use DI to set up.

Testing
We talked about the techniques that are at our disposal for validating the quality of your app. Of course using unit tests should be a no-brainer to developers, and there are actually some nice scenarios for testing the behaviour of your ViewModels and other logic in your app. These unit tests, being independent and mostly having their dependencies stubbed (another advantage of using DI is that it makes stubbing a bit easier), can give you the quickest feedback during your development cycle.

But an important part of your app will be the UI and that actually runs on the device. This has always been hard to test and we had a look at what Xamarin Test Cloud has to offer and the UITest API’s that you use to drive those tests. In a recent talk, I used this test pyramid diagram to show the stack I like to use for testing mobile apps:

mobile-test-stack.png

Note that I still think that there will always be a certain amount of manual testing involved for the more complex cases. And specifically those cases where you want to check the behaviour of your app under different circumstances, such as actually being on the move through tunnels or other low connection situations, or being out in the field to make actual pictures with the camera. Manual field tests by the team and beta test platforms like HockeyApp, Apple TestFlight and Google Play Beta are excellent tools for this.

Xamarin sure knows how to throw a party… #XamarinEvolve

A photo posted by Roy Cornelissen (@roycornelissen) on

After the training it was time for some relaxation at LaFayette’s. Excellent food and great Southern style live music, and all the familiar faces from the Xamarin community there. Great to see everyone again! Really looking forward to the next few days!

To infinity, and beyond!
On Sunday, we had some spare time, so we spent the day at the NASA Kennedy Space Center. Wow what an amazing trip! It was incredible to see the huge rockets, it’s impossible to fathom how big they are until you see them. The same goes for the Space Shuttle. The Atlantis Space Shuttle is on display and you can see it up close. Super cool!

Awesome, the Atlantis Space Shuttle #nasa

A photo posted by Roy Cornelissen (@roycornelissen) on

Rocket science

A photo posted by Roy Cornelissen (@roycornelissen) on

The biggest surprise came when we went on the bus tour to the actual launch site. Again, it’s impossible to fathom the scale of the site and the equipment there that’s used for space travel. At the end we got a great show about the Apollo missions. The actual control center used for the Apollo mission is there on display. And then there’s the overwhelming and HUGE replica of the Apollo rocket.

Appollo Control Center #nasa

A photo posted by Roy Cornelissen (@roycornelissen) on

And the coolest thing was: our Uber driver who took us back to the hotel was an engineer on the Space Shuttles for 30 years! So he could give us some fun behind-the-scenes insights. Did you know for example that there was an actual Coca Cola machine installed in one of the shuttles? That was to test the effects of carbonation in space. But since Coca Cola is a commercial company, NASA was not allowed to talk about that😉

Oh and don’t you just love these vintage posters?

Love these vintage graphic posters #nasa

A photo posted by Roy Cornelissen (@roycornelissen) on

NASA is recruiting #nasa

A photo posted by Roy Cornelissen (@roycornelissen) on

Everybody gets a Xamarin!

Rohancharge
Standard

This week at Microsoft’s //build/ 2016 conference in San Francisco, Scott Guthrie shared more details about the Xamarin acquisition and what this means for developers on the Microsoft stack. The keynote is worth checking out, also for the great Azure content. More interesting details about what Xamarin has in the works can be found in Miguel de Icaza’s session. Or you can watch the distilled announcement here:

In short, Microsoft has made the Xamarin tools available to everyone. If you have a Visual Studio Professional or Enterprise edition, Xamarin is included at no extra cost. Moreover, it’s also available as a completely free Community Edition, under the same Microsoft license terms (small teams, OSS developers and students). Wow!

Even though the technology is widely regarded as excellent, as Miguel states in his talk: Xamarin used to be a bit of a niche product because of the pricing. And let’s be honest, they were steep and it turned people off, even though you could easily build a solid business case in terms of money and time saved due to higher developer productivity. But this means that Microsoft has removed a big barrier for a lot of companies and developers to adopt Xamarin! Not only that, but the fact that Microsoft is fully behind the Xamarin approach is very beneficial for customers who were betting their mobile development approach on Xamarin.

This interview with Nat Friedman on TechCrunch is an interesting read if you want to learn more about the acquisition.

Open source FTW
One of the most notable changes within Microsoft lately is their big support for open source. Microsoft emphasised this by open sourcing their .NET Framework, which has received many pull requests and active contributions since. This lead to .NET being revamped to a cross platform runtime and framework which runs on Windows, Mac and Linux as well (my colleague Alex Thissen wrote an interesting article about .NET Core in the second issue of Xpirit Magazine). This is something that Mono and Xamarin have already been pioneering over the past years. It’s nice to see these things come together and the teams combining forces to move things forward. It’s a bit soon to tell what will happen with Mono in the future and whether it will merge with .NET over time, but for now it’s important to know that Mono has been re-lincensed under the MIT license, which is a pretty big deal in itself.

Moreover, Nat Friedman also announced that the whole Xamarin framework, their customized Mono runtime and Xamarin.Forms will be contributed to the OSS .NET Foundation. How cool is that!

Full cycle mobile DevOps
With the acquisition of Xamarin and – earlier – HockeyApp, Microsoft now has a pretty strong full cycle DevOps story for mobile development. Obviously the development story with cross platform C# already was strong, integration into VSTS for continuous integration is very powerful and continuous deployment to HockeyApp for internal enterprise apps is also quite easy. Check out my colleague Geert’s blog series on this topic. TestCloud remains an excellent way to mitigate test risks with their vast array of devices.

Over time, we’ll see Xamarin Insights integrated into HockeyApp for .NET native crash reporting and analytics. Xamarin Insights is a very nice product and their native support for .NET exception stack traces and ability to use the SDK in a shared PCL project is pretty powerful. I expect that after merging with HockeyApp, the pricing model for the analytics part will be much more attractive as well.

It would be cool to see more seamless integration of tools like Fastlane for easy and automated submission to public AppStores, etcetera.

Everyone can do Xamarin now! (?)
This all means that every .NET developer can do mobile development with Xamarin now.

Or at least, technically… Moving into mobile development – especially iOS and Android – coming from a Windows, ASP.NET, back-end development background isn’t as easy as 1-2-3.

To me the beauty of Xamarin has always been that they provide unrestricted access to every native API that is also available to Swift, Objective-C and/or Android Java developers. In my opinion, this still yields the highest quality apps while still being able to reuse a good portion of your code across platforms. The power lies in the fact that you can play with the level of reuse vs. native platform specific code as it suits you as opposed to going all in with UI abstractions and reuse all of your code. Abstraction in software development is a slippery slope and Xamarin allows you to stop abstracting if you feel it goes too far. I sincerely hope that this direct-access-to-native-API’s approach will remain a core feature of the Xamarin product, and we won’t be forced into a “UWP for all platforms” model.

Having access to all the native API’s lets you leverage the unique capabilities of the underlying OS-es. Apple Pay, Touch-ID, etcetera. But this requires deep knowledge of how these OS-es work and how to use their API’s. iOS and Android are very different beasts when it comes to their architecture and solutions for problems. This means that in my opinion, there will still be iOS developers, Android developers and Windows Developers, even though they’re all working with the same language. Sure you can master them all, but I think a good mix of specialism and multi-disciplinary teams are the way to go. Mobile devs are just like normal humans, and can be pretty biased about their platform of preference. This sometimes makes for great and interesting discussions on how to solve a particular use case on all platforms, aside from the occasional fun banter about the Windows Mobile app gap, not being able to open links on iOS, or the immense device and OS fragmentation in the Android world.

Rohancharge

In any case, there will be a whole army of .NET developers coming to the Xamarin platform and there will be a huge demand for knowledge. Xamarin’s Developer Center has been revamped and it looks very nice. It’s a great resource for learning how to build apps with Xamarin and they do an excellent job explaining the native API’s and how to leverage them from C#. But over the years I have found that presenting at user groups and conferences and delivering in-person training is also a great way to share knowledge.

Both Marcel and I at Xpirit have been heavily invested in Xamarin since the early days and we’ve had the opportunity to fly around the world to speak about Xamarin. I look forward to continue sharing our knowledge. Our team was recently enforced with Geert joining Xpirit,  and we’re dedicated to helping developers and customers do professional mobile development with Xamarin and Microsoft.

Come meet us and dive in head first with us at one of the following opportunities:

My hopes and expectations
It surely looks like Microsoft is invested in making the Xamarin tools a first class citizen in the .NET developer stack and Visual Studio ecosystem. We can expect deeper integration of Xamarin into Visual Studio, and Miguel already showed a glimpse of that with an iOS Simulator running on Windows. This sparked some debate about whether or not this is an actual simulator running natively on Windows, but if you listen carefully, Miguel explains that it is a simulator window remoted to a Mac. I think this trick is similar to how Xamarin does it’s build & app packaging for iOS with a remote build host over SSH:

FullSizeRender 2

I’ve seen a setup like this at many companies, where Windows PC’s were the standard developer setup, and Mac’s are considered “exotic”. Using a Mac Mini as a remote build host works ok, but if you wanted to test and debug, you needed to switch to that Mac physically or access it via VNC. That was sub-optimal and this solution is pretty sweet.  I don’t think we’ll be able to have a native iOS developer story without a Mac because of Apple restrictions regarding their SDK but this promises to make the developer experience for a Windows based developer a whole lot smoother. I think Marcel will be happy🙂

It’s no secret that I’m more biased towards iOS and developing on the Mac. Using Xamarin Studio, sometimes switching to Xcode for the Interface Builder and the pleasant experience with the much less bloated Xamarin Studio IDE has become more natural to me than working from Windows and I’ve come to prefer it. With Microsoft pushing towards developer tools for Linux and Mac (VS Code), it looks like Xamarin Studio is also here to stay, and hopefully with the same level of investment to push the product ahead. Who knows, maybe Xamarin Studio might become the official Visual Studio IDE for the Mac one day🙂

In his //build/ session, Miguel showed off Xamarin Workbooks, which is based on the Xamarin Inspector. It looks very sweet as a test-bench for C# code and documentation tool. But even better: it can now be used to inspect and play with a live running app on the simulator! That is awesome as it shortens the dev/build/run/debug cycle tremendously. I hope that it will become a core part of the developer experience from within Xamarin Studio / Visual Studio but for now it has already saved me a lot of time this week while trying it out.

I also have good hopes that the original character of Xamarin’s approach (full access to native API’s) will remain intact. UWP sounds like a good idea for the Windows platform but Xamarin has always stressed that Xamarin.Forms has very specific use cases. It’s not a one-size-fits-all solution, and frankly that’s the main thing I’ve been arguing against ever since I chose to go with Xamarin as opposed to Cordova, Titanium or others. So while I do expect that there will be something like a UWP for Windows, iOS and Android, it cannot be the only way to develop native mobile apps.

More dots to come…
Evolve 2016 promises to be a fantastic conference and a big party to celebrate the future of Xamarin at Microsoft. I hope to see you there.

Nat Friedman wasn’t kidding when he replied to my Instagram musing:

#Xamarin timeline. Proud to have been along for the ride since even before that first dot 👍

A photo posted by Roy Cornelissen (@roycornelissen) on

Here’s to more dots!

GMImagePicker ported to Xamarin.iOS

FullSizeRender
Standard

TL;DR
I ported GMImagePicker to C#. Code here, Nuget here. Happy coding!

This past week I was working on a Xamarin project where we need support for selecting multiple images and/or taking pictures and uploading them to a backend service. The default UIImagePicker control in iOS is ok but not very versatile. It can take a picture with the camera, or lets you select a single image from your gallery but that’s about it. Furthermore, working with the resulting images is quite cumbersome as you’re working with large UIImage objects in memory. A lot of performance and memory issues can happen if you’re not careful.

In order to deal with photos and videos more efficiently and in a much richer manner, Apple introduced the PhotoKit API in iOS 8. Mike Bluestein has written a nice introductory post on this API on the Xamarin blog, so I’m not going to repeat this.

In short, PhotoKit works with the notion of PHAsset objects, which are basically descriptors for media files on the device. There are API’s to query different photo galleries, etcetera. Only once you actually need the image for display or other purposed do you have to retrieve the image using the PHAsset descriptor. Very efficient.

Many apps, such as the Facebook app, allow users to select multiple images in a user friendly manner, and maybe even add pictures on the go by providing access to the camera while they are browsing their gallery. This is something that we also wanted to add to our app. Luckily, there are some nice open source projects around that implement just that. One of the nicest ones is the GMImagePicker component by Guillermo Muntaner Perelló, which uses the PhotoKit API under the hood. The user experience looks like this:

gmimagepickerdemo

That’s slick! You can browse through several collections, and the control is highly customizable, and even contains localized texts for labels, buttons and dialogs. Only, it’s written in Objective-C…

I had two options: bind the API using Xamarin’s Objective Sharpie or port it verbatim to C#. I chose to port it, mainly to have full control over the inner workings of the control and to not have to pull in a “foreign” language into the project. The port has complete feature parity with the Objective-C version and I tried to iron out as many issues as I could. It seems to be working pretty smoothly in my Xamarin app.

The code is up on GitHub and you can use the control by either downloading the code and including the .csproj in your project, or install the Nuget package in your Xamarin.iOS app:

Install-Package GMImagePicker.Xamarin

As I said, the GMImagePicker control is highly customizable. You can change its appearance by specifying colors for different parts of the UI, and you can provide custom titles and confirmation prompts. It’s also possible to filter and limit the types of assets you want the user to select. The whole range of options can be found in the sample app that comes with the control. Here is an overview:

var picker = new GMImagePickerController {
Title = "Custom Title",
CustomDoneButtonTitle = "Finished",
CustomCancelButtonTitle = "Nope",
CustomNavigationBarPrompt = "Take a new photo or select an existing one!",
ColsInPortrait = 3,
ColsInLandscape = 5,
MinimumInteritemSpacing = 2.0f,
DisplaySelectionInfoToolbar = true,
AllowsMultipleSelection = true,
ShowCameraButton = true,
AutoSelectCameraImages = true,
ModalPresentationStyle = UIModalPresentationStyle.Popover,
MediaTypes = new [] { PHAssetMediaType.Image },
// Other customizations to play with:
//ConfirmSingleSelection = true,
//ConfirmSingleSelectionPrompt = "Do you want to select the image you have chosen?",
//PickerBackgroundColor = UIColor.Black,
//PickerTextColor = UIColor.White,
//ToolbarBarTintColor = UIColor.DarkGray,
//ToolbarTextColor = UIColor.White,
//ToolbarTintColor = UIColor.Red,
//NavigationBarBackgroundColor = UIColor.Black,
//NavigationBarTextColor = UIColor.White,
//NavigationBarTintColor = UIColor.Red,
//PickerFontName = "Verdana",
//PickerBoldFontName = "Verdana-Bold",
//PickerFontNormalSize = 14.0f,
//PickerFontHeaderSize = 17.0f,
//PickerStatusBarStyle = UIStatusBarStyle.LightContent,
//UseCustomFontForNavigationBar = true,
};

// You can limit which galleries are available to browse through
picker.CustomSmartCollections = new [] {
PHAssetCollectionSubtype.SmartAlbumUserLibrary,
PHAssetCollectionSubtype.AlbumRegular
};

// Event handling
picker.FinishedPickingAssets += Picker_FinishedPickingAssets;
picker.Canceled += Picker_Canceled;

// Other events to implement in order to influence selection behavior:
// Set EventArgs::Cancel flag to true in order to prevent the action from happening
picker.ShouldDeselectAsset += (s, e) => { /* allow deselection of (mandatory) assets */ };
picker.ShouldEnableAsset += (s, e) => { /* determine if a specific asset should be enabled */ };
picker.ShouldHighlightAsset += (s, e) => { /* determine if a specific asset should be highlighted */ };
picker.ShouldShowAsset += (s, e) => { /* determine if a specific asset should be displayed */ };
picker.ShouldSelectAsset += (s, e) => { /* determine if a specific asset can be selected */ };
picker.AssetSelected += (s, e) => { /* keep track of individual asset selection */ };
picker.AssetDeselected += (s, e) => { /* keep track of individual asset de-selection */ };

// The GMImagePicker can be treated as a PopOver as well:
var popPC = picker.PopoverPresentationController;
popPC.PermittedArrowDirections = UIPopoverArrowDirection.Any;
popPC.SourceView = gmImagePickerButton;
popPC.SourceRect = gmImagePickerButton.Bounds;

await PresentViewControllerAsync(picker, true);

The extensibility is very convenient. For example: if you want to set a maximum to the total size of the images you want to allow the user to select, you can handle the AssetSelected event, keep track of the total size selected, and handle ShouldSelectAsset, to prevent selection if a maximum threshold has been reached. This is exactly what we wanted to have in our app.

Once the user has finished selecting assets, you can use a PHImageManager to retrieve the actual images in whatever size you like:

void FinishedPickingAssets (object s, MultiAssetEventArgs e)
{
  PHImageManager imageManager = new PHImageManager();

  foreach (var asset in e.Assets) {
    imagePreview.Image = null;

    imageManager.RequestImageForAsset (asset, 
      new CGSize(asset.PixelWidth, asset.PixelHeight), 
      PHImageContentMode.Default, 
      null, 
      (image, info) => {
        // do something with the image (UIImage), e.g. upload to server
        // you can get the JPEG byte[] via image.AsJPEG()
      });
  }
}

Very nice, and it’s now available for Xamarin.iOS developers as well🙂

photo-1437419764061-2473afe69fc2

Photo by Andrew Illarionov (https://unsplash.com/photos/-WW8jBak7bo)

Many thanks to Guillermo for letting me port his excellent code and publish it. I’d love to hear your feedback on the code and would love to see your PR’s for improvements.