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: release

  • Using Different Entitlements for Debug and Release Modes in .NET MAUI – iOS

    This content has 7 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.

    When developing a mobile app using .NET MAUI, particularly for iOS, it’s essential to configure your application differently for debug and release modes. One of these differences is the APS-environment setting, which dictates how your app communicates with Apple Push Notification services (APNs) during development and production.

    What is Entitlements.plist?

    The Entitlements.plist is a property list (plist) file that defines various capabilities or entitlements for your app. Entitlements are special permissions that allow your app to use certain services provided by iOS, such as iCloud, In-App Purchases, or push notifications.

    For push notifications, the Entitlements.plist file contains the APS-environment key, which indicates to Apple whether your app is in development or production mode. Based on this, the app uses either the sandbox or production APNs.

    What is APS-environment?

    The APS-environment (Apple Push Services environment) is an entitlement used to specify the environment for push notifications. This entitlement informs Apple’s servers whether the app is running in a development environment or in production, determining which server to send the notifications through:

    • Development APS-environment: Used for testing push notifications during the app’s development phase. These notifications go through Apple’s sandbox APNs server.
    • Production APS-environment: Used for apps that have been published and distributed through the App Store. Notifications go through Apple’s production APNs server.

    This configuration helps separate testing from live user interactions and avoids accidental notification delivery to users during testing.

    Configuring Different APS-environments for Debug and Release

    To configure different environments for Debug and Release modes in your .NET MAUI project, you can modify your .csproj file as follows:

    <PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net8.0-ios|AnyCPU'">
      <CodesignEntitlements>Platforms\iOS\Entitlements.plist</CodesignEntitlements>
    </PropertyGroup>
    
    <PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net8.0-ios|AnyCPU'">
      <CodesignEntitlements>Platforms\iOS\Entitlements-Production.plist</CodesignEntitlements>
    </PropertyGroup>
    
    

    It’s important to ensure that both Entitlements.plist and Entitlements-Production.plist files are not included in the build by accident. This can be achieved by setting their Build Action to None:

    1. Right-click on each file (Entitlements.plist and Entitlements-Production.plist) in Visual Studio.
    2. Select Properties.
    3. Set the Build Action to None.

    This step ensures that the files are correctly associated with your app for code-signing purposes but are not compiled into the app bundle unnecessarily.

    (Update) Or you can simply use this approach in your .csproj file which is far more easier:

    	<ItemGroup Condition="$(TargetFramework.Contains('-ios'))">
    		<CustomEntitlements Include="aps-environment" Condition="'$(Configuration)' == 'Release'" Type="String" Value="production" />
    		<CustomEntitlements Include="aps-environment" Condition="'$(Configuration)' == 'Debug'" Type="String" Value="development" />
    	</ItemGroup>
    
  • .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.