Lumino Webdesign og SEO
Nettleseren din må oppgraderes. Du har Internet Explorer version {%ieversion%}. Gå til www.microsoft.com for å laste ned siste versjon av Internet Explorer.

Tech blogg

Dark mode for iOS using Xamarin

iPhone Dark Mode

I recently implemented dark mode in iOS for an app using Xamarin for app-development. It turned out to be quite a bit of work, as all styles had to be changed / rewritten, and I had to go through all the code in the entire app and change styling - either background color or text color or what not.

In Xamarin, you also have to use the "Experimental flag" when implementing dark mode. To set this flag, I followed the instructions in this article by Microsoft - https://docs.microsoft.com/en-us/xamarin/xamarin-forms/internals/experimental-flags. 

As you can see in this article, you are told to set the "AppTheme_Experimental" flag in your code. There are several  ways to do this, and I unfortunately used this code in my AppDelegate.cs class in my DoStartupWork() method to enable the flag with a line of code like this: "Xamarin.Forms.Forms.SetFlags("AppTheme_Experimental");". This worked all fine while in debug mode - AND using the "Linker behaviour: Don't Link". Before publishing my app, I wanted to test the new dark mode functionality on a real device. I then switched to a new setting with "Linker behaviour: Link Framework SDKs Only", and my app started crashing right after the launch screen was displayed...

It actually took me a while to figure out this error. It turned out that the explanation is in the above mentioned article. The key here are the words "platform project". They state the following:

  1. Enabling an experimental flag in your platform projects must occur before the Forms.Init method is invoked. (I did this right - enabled in AppDelegate.cs)
  2. The Xamarin.Forms.Forms.SetFlags method can be used to enable an experimental flag in your platform projects.

What I didn't realize was that they had another section where they talked about how to enable an experimental flag for a shared code project. And the key here is "shared" as opposed to "platform". So for shared code projects, they state the following:

  1. The Device.SetFlags method can be used to enable an experimental flag in the App class in your shared code project

Based on this information, I then added the code "Device.SetFlags(new string[]{ "AppTheme_Experimental" });" in my App.xaml.cs - remember to put it before the InitializeComponent() method (it should occur before the Forms.Init method is invoked). And I of course had to remove the previous line of code in the AppDelegate.cs class.

Voila! It worked again. No more crashes.

Well, you can use Xamarin to develop shared code projects (i.e., code shared between iOS, Android and UWP), or you can use Xamarin to develop platform projects (i.e., separate code for iOS, Android, UWP). The thing is that in shared code projects, the file AppDelegate.cs is also present...

André Vold

Tech blogg
André Vold

Her er en rask liten BLOGGER BIO for å fortelle litt om min bakgrunn - og hvorfor jeg valgte programmering som fagfelt.

Jeg vokste opp i Norge, men gikk på universitet i USA. Jeg er sivilingeninør med grad innen "Computer Engineering" fra Arizona State University. Etter utdannelsen flyttet jeg tilbake til Norge, begynte å arbeide på Norsk Data og senere IBM, og tok videreutdannelse på BI innen Master of Management. Etter flere år som divisjonsdirektør i IBM Norge, valgte jeg å starte e-læringsfirmaet Apropos Internett AS . Senere startet jeg også ViroSafe Norge AS som importerer og distribuerer anti-malware og anti-virus software og hardware.

Det har alltid vært essensielt for meg å holde meg oppdatert innen teknologiske endringer og trender - ikke bare for å kunne holde programmeringskunnskaper på topp, men også for min suksess som gründer.

Lumino blogger omfatter en rekke temaer som har vært essensiell for min virksomhet, og som derfor kan være relevant for din.
Forsiden
Referanser
Tech blogg
Personvern

Søkeresultater