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
:
- Right-click on each file (
Entitlements.plist
andEntitlements-Production.plist
) in Visual Studio. - Select Properties.
- 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>
Leave a Reply