András Tóth‘s professional blog
banditoth.net

Hey there 👋, I’m banditoth a .NET MAUI developer from Hungary.
I write about software development with .NET technologies.

You can find me on:
LinkedIn | Github | StackOverflow | X / Twitter | Threads

Tag: .NET MAUI

  • Azure Pipelines error after macOS / iOS update when building iOS apps with .NET MAUI

    If you are facing problems after a new version of macOS, or iOS have been released, stay tuned.

    In this example, I’m having issues with the new update of iOS 18 and macOS Sequioa. Some days or weeks are needed from Microsoft side to have a vmPool in the cloud to build your iOS apps with the latest SDKs, so theres a possibility that you might encounter this problem on some fresher updates aswell.

    So how the error looks like?

    ILLINK : error MT2362: The linker step 'ClassHandleRewriter' failed during processing: One or more errors occurred. (The type 'MapKit.MKSelectionAccessory' (used as a return type in MapKit.MKMapView/_MKMapViewDelegate.GetSelectionAccessory) is not available in iOS 17.2 (it was introduced in iOS 18.0). Please build with a newer iOS SDK (usually done by using the most recent version of Xcode). 
      		) (The type 'UIKit.UITextFormattingViewController' (used as a parameter in UIKit.UITextView/_UITextViewDelegate.DidBeginFormatting) is not available in iOS 17.2 (it was introduced in iOS 18.0). Please build with a newer iOS SDK (usually done by using the most recent version of Xcode).
      		) (The type 'UIKit.UITextFormattingViewController' (used as a parameter in UIKit.UITextView/_UITextViewDelegate.DidEndFormatting) is not available in iOS 17.2 (it was introduced in iOS 18.0). Please build with a newer iOS SDK (usually done by using the most recent version of Xcode).
      		) (The type 'UIKit.UITextFormattingViewController' (used as a parameter in UIKit.UITextView/_UITextViewDelegate.WillBeginFormatting) is not available in iOS 17.2 (it was introduced in iOS 18.0). Please build with a newer iOS SDK (usually done by using the most recent version of Xcode).
      		) (The type 'UIKit.UITextFormattingViewController' (used as a parameter in UIKit.UITextView/_UITextViewDelegate.WillEndFormatting) is not available in iOS 17.2 (it was introduced in iOS 18.0). Please build with a newer iOS SDK (usually done by using the most recent version of Xcode).
      		) (The type 'UIKit.UITab' (used as a parameter in UIKit.UITabBarController/_UITabBarControllerDelegate.AcceptItemsFromDropSession) is not available in iOS 17.2 (it was introduced in iOS 18.0). Please build with a newer iOS SDK (usually done by using the most recent version of Xcode).
      		) (The type 'UIKit.UITab' (used as a parameter in UIKit.UITabBarController/_UITabBarControllerDelegate.DidSelectTab) is not available in iOS 17.2 (it was introduced in iOS 18.0). Please build with a newer iOS SDK (usually done by using the most recent version of Xcode).
      		) (The type 'UIKit.UITab' (used as a parameter in UIKit.UITabBarController/_UITabBarControllerDelegate.DidSelectTab) is not available in iOS 17.2 (it was introduced in iOS 18.0). Please build with a newer iOS SDK (usually done by using the most recent version of Xcode).
      		) (The type 'UIKit.UITabGroup' (used as a parameter in UIKit.UITabBarController/_UITabBarControllerDelegate.DisplayOrderDidChangeForGroup) is not available in iOS 17.2 (it was introduced in iOS 18.0). Please build with a newer iOS SDK (usually done by using the most recent version of Xcode).
      		) (The type 'UIKit.UITab' (used as a parameter in UIKit.UITabBarController/_UITabBarControllerDelegate.GetDisplayedViewControllers) is not available in iOS 17.2 (it was introduced in iOS 18.0). Please build with a newer iOS SDK (usually done by using the most recent version of Xcode).
      		) (The type 'UIKit.UITab' (used as a parameter in UIKit.UITabBarController/_UITabBarControllerDelegate.GetOperationForAcceptingItemsFromDropSession) is not available in iOS 17.2 (it was introduced in iOS 18.0). Please build with a newer iOS SDK (usually done by using the most recent version of Xcode).
      		) (The type 'UIKit.UITab' (used as a parameter in UIKit.UITabBarController/_UITabBarControllerDelegate.ShouldSelectTab) is not available in iOS 17.2 (it was introduced in iOS 18.0). Please build with a newer iOS SDK (usually done by using the most recent version of Xcode).
      		) (The type 'UIKit.UITab[]' (used as a parameter in UIKit.UITabBarController/_UITabBarControllerDelegate.VisibilityDidChangeForTabs) is not available in iOS 17.2 (it was introduced in iOS 18.0). Please build with a newer iOS SDK (usually done by using the most recent version of Xcode).
      		)
    

    Solution after the proper vmImages are released by Microsoft:

    To resolve this issue, you need to update the macOS image used in your Azure Pipelines to the latest version. This ensures that the build environment uses the most recent version of Xcode, which includes the necessary iOS SDKs.

    Here’s how you can update your Azure Pipelines configuration:

    • Open your Azure Pipelines YAML file: Locate the YAML file that defines your pipeline configuration.
    • Update the vmImage: Change the vmImage to macOS-latest to ensure that the latest macOS version is used, which includes the most recent Xcode and iOS SDKs.
    pool:
      vmImage: 'macOS-latest'
    
    • Save and commit the changes: Save the updated YAML file and commit the changes to your repository.
    • Run the pipeline: Trigger a new build in Azure Pipelines to verify that the issue is resolved.

    By updating the vmImage to macOS-latest, you ensure that your build environment is using the latest tools and SDKs, which should resolve the linker errors related to unavailable types.

    Solution until the proper vmImages are not present:

    Modify your pipeline, and don’t forget to add comments on the modified pipeline!

    • Open your Azure Pipelines YAML file: Locate the YAML file that defines your pipeline configuration.
    • Update the YAML file:
    pool: 
         vmImage: 'macOS-14'
    # András @ 24.10.04: Explicit version needed until macos15 vmimage is being released. Use latest when possible
        steps:
          - task: CmdLine@2
            displayName: 'Select XCode 16 explicitly'
            inputs:
              script: 'sudo xcode-select -s /Applications/Xcode_16.app'
    # András @ 24.10.04: Explicit version code needed for XCode. Remove this task when possible
    
          - task: CmdLine@2
            displayName: 'Install MAUI Workload'
            inputs:
              script: 'dotnet workload install maui --version 8.0.402'
    # András @ 24.10.04: Explicit version needed until macos15 vmimage is being released. Use no --version tag if possible
    
    • Save and commit the changes: Save the updated YAML file and commit the changes to your repository.
    • Run the pipeline: Trigger a new build in Azure Pipelines to verify that the issue is resolved.
  • .NET MAUI Android: OverrideBackButtonPress not being hit.

    You might encounter a scenario where the OverrideBackButtonPress method in your Page is not being triggered on Android devices. This can be a frustrating issue, but there’s a straightforward solution that involves modifying your AndroidManifest.xml file.

    The predictive back gesture feature in Android can indeed affect how back button presses are handled in your application. Learn more at: https://developer.android.com/guide/navigation/custom-back/predictive-back-gesture

    Predictive Back Gesture

    Android’s predictive back gesture allows users to preview the destination or action that will occur when they complete a back gesture. In .NET MAUI, the OverrideBackButtonPress method allows you to handle the back button press event in your application. However, if this method is not being called, it could be due to a specific setting in your AndroidManifest.xml file.

    Disabling Predictive Back Gesture

    To ensure your custom back button handling works as expected, you need to disable the predictive back gesture by setting the android:enableOnBackInvokedCallback attribute to false in your AndroidManifest.xml file. This prevents the system from intercepting the back button press and allows your application to handle it.

    <application
        android:label="YourAppName"
        android:icon="@mipmap/ic_launcher"
        android:enableOnBackInvokedCallback="false">
        <!-- Other settings -->
    </application>
    
    

  • .NET MAUI iOS – Can’t launch the app, crashes on splash screen error

    This content has 9 months. Some of the information in this post may be out of date or no longer work. Please, read this page keeping its age in your mind.

    If you are facing issues launching your iOS application in VS Code, then try to analyse the Debug Console of your application.
    If you see things like this:

    Loaded assembly: /private/var/containers/Bundle/Application/50529075-A03E-45EC-99F6-0A539036E226/app.app/Newtonsoft.Json.dll
    Loaded assembly: /private/var/containers/Bundle/Application/50529075-A03E-45EC-99F6-0A539036E226/app.app/System.Reflection.Emit.Lightweight.dll
    Loaded assembly: /private/var/containers/Bundle/Application/50529075-A03E-45EC-99F6-0A539036E226/app.app/System.Reflection.Emit.ILGeneration.dll
    Loaded assembly: /private/var/containers/Bundle/Application/50529075-A03E-45EC-99F6-0A539036E226/app.app/System.Reflection.Primitives.dll
    Loaded assembly: /private/var/containers/Bundle/Application/50529075-A03E-45EC-99F6-0A539036E226/app.app/System.Data.Common.dll
    Loaded assembly: /private/var/containers/Bundle/Application/50529075-A03E-45EC-99F6-0A539036E226/app.app/Syncfusion.Maui.Inputs.dll
    Loaded assembly: /private/var/containers/Bundle/Application/50529075-A03E-45EC-99F6-0A539036E226/app.app/ZF.Packages.Maui.Fonts.dll
    Loaded assembly: /private/var/containers/Bundle/Application/50529075-A03E-45EC-99F6-0A539036E226/app.app/ZF.Packages.Maui.Views.Alerts.dll
    Loaded assembly: /private/var/containers/Bundle/Application/50529075-A03E-45EC-99F6-0A539036E226/app.app/Refit.HttpClientFactory.dll
    Loaded assembly: /private/var/containers/Bundle/Application/50529075-A03E-45EC-99F6-0A539036E226/app.app/Microsoft.Extensions.Http.dll
    Loaded assembly: /private/var/containers/Bundle/Application/50529075-A03E-45EC-99F6-0A539036E226/app.app/MetroLog.Maui.dll
    

    And then your application suddenly crashes showing the splashscreen, then the debugger might be slow.

    XCode 15 have problems with debugging. If you have “Connect via network” enabled on your XCode settings under Devices and Simulators, than this might be the problem. Even if you are connecting your phone wired, it starts the application debugging via wifi.
    Try updating XCode to 15.4, and update your OS to macOS Sonoma 15.4 aswell

    You can countercheck this problem by disabling the wifi on your physical device. In this case the app installs, but crashes instantly when trying to launch it.

    Additionally in Visual Studio code the solution you can disable some settings in the C# extension’s settings the Debug > Logging to speed up the loading progress when launching your app.

  • Publishing .NET MAUI Apps with VS Code

    This content has 1 year. Some of the information in this post may be out of date or no longer work. Please, read this page keeping its age in your mind.

    In this tutorial, I will guide you through the step-by-step process of publishing .NET MAUI apps using Visual Studio Code and the ‘.NET MAUI – Archive / Publish tool’ extension by me. This extension simplifies the publishing process by providing a user-friendly interface within VS Code.

    Without the help of an extension

    You will need to dive into a terminal, and give out the following commands, based on which platform you want to build for.

    # Android:
    dotnet publish -f net8.0-android -c Release -p:AndroidKeyStore=true -p:AndroidSigningKeyStore={filename}.keystore -p:AndroidSigningKeyAlias={keyname} -p:AndroidSigningKeyPass={password} -p:AndroidSigningStorePass={password}
    # iOS:
    dotnet publish -f net8.0-ios -c Release -p:ArchiveOnBuild=true -p:RuntimeIdentifier=ios-arm64 -p:CodesignKey="Apple Distribution: John Smith (AY2GDE9QM7)" -p:CodesignProvision="MyMauiApp"
    

    You can learn more, how to do it without my extension at:
    https://learn.microsoft.com/en-us/dotnet/maui/ios/deployment/publish-cli?view=net-maui-8.0
    and
    https://learn.microsoft.com/en-us/dotnet/maui/android/deployment/publish-cli?view=net-maui-8.0

    But don’t waste your time. I’ve put together a Visual Studio Code extension for you that will easily save you those unnecessary lines and allow you to publish from the UI.

    Step 1: Install VS Code Extension


    Visit the VS Code Marketplace and install the ‘.NET MAUI – Archive / Publish tool’ extension by ‘banditoth’.

    You might be required to reload your VS Code instance.

    Step 2: Open Your .NET MAUI Project

    Launch Visual Studio Code and open your .NET MAUI project.

    Step 3: Access the Command Palette

    Press Ctrl+Shift+P (Windows/Linux) or Cmd+Shift+P (Mac) to open the command palette in Visual Studio Code.

    Step 4: Choose Publish Android or Publish iOS

    Type ‘MAUI Publish’ in the command palette. You will see two options: ‘MAUI: Publish Android’ and ‘MAUI: Publish iOS’. Select the one that corresponds to your target platform.

    Publishing for Android:

    The extension will prompt you to choose between a signed or non-signed binary. Select your preferred option.

    Next, choose the package format – either apk (Android Package) or aab (Android App Bundle).

    If signing is required (for a signed binary), the extension will list all installed keystore files. Choose the appropriate keystore.

    Enter the keystore password when prompted.

    The extension will start the publishing process, and you’ll see progress information directly in the VS Code output.

    Publishing for iOS:

    Select ‘MAUI: Publish iOS’ from the command palette.

    The extension will ask for the code signing identity. Choose the desired code signing identity from the available options.

    Next, choose a provisioning profile to sign the app.

    The extension will initiate the publishing process for iOS, displaying progress information in the VS Code output.

    Conclusion

    With the ‘.NET MAUI – Archive / Publish tool’ extension, publishing your .NET MAUI apps for Android and iOS becomes a straightforward process within Visual Studio Code. You no longer need to manually execute complex CLI commands; instead, you can leverage the extension’s user-friendly interface for a seamless publishing experience. Enjoy the convenience and efficiency of this simplified workflow for your .NET MAUI projects!

    Support the project

    You can find more information about how to contribute on this project at the project’s github page: https://github.com/banditoth/maui-archiver-vscode

  • .NET MAUI iOS – Azure Pipelines error: ‘x’ is not available in iOS 16

    This content has 1 year. Some of the information in this post may be out of date or no longer work. Please, read this page keeping its age in your mind.

    The Error: The error message suggests that the ‘UIKit.UISceneSessionActivationRequest’ type, used as a parameter in ‘UIKit.UIApplication.ActivateSceneSession,’ is not available in iOS 16.2 and was introduced in iOS 17.0. This discrepancy indicates a version misalignment in the development environment, specifically with the iOS SDK and Xcode.

    Root cause

    The root cause of this error lies in the version of the macOS image used in the Azure Pipelines configuration. By default, the ‘macOS-latest’ image is pulled, which corresponds to macOS 12 (at the time of the blog post). However, the .NET MAUI app with Azure Pipelines requires macOS v13 to work seamlessly, as it aligns with the necessary dependencies for iOS development.

    Resolution

    To resolve this error, developers need to update the macOS image specified in the Azure Pipelines configuration. Instead of using ‘macOS-latest,’ the configuration should be modified to use ‘macOS-13.’ This ensures that the appropriate version of macOS is utilized during the build process, addressing the compatibility issues with iOS 16.2 and the required UIKit types.

    Step-by-Step

    -Open your Azure Pipelines configuration file (typically named azure-pipelines.yml).
    -Locate the section where the macOS image is specified. It might look something like this:

    pool:
      vmImage: 'macOS-latest'
    

    -Update the image reference to ‘macOS-13’:

    pool:
      vmImage: 'macOS-13'
    

    -Save the changes to the configuration file.
    -Commit the updated configuration file to your version control system (e.g., Git).
    -Trigger a new build in Azure Pipelines, and the updated macOS image will be used.