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

  • Prepare your Windows servers for Apple’s APNs certificate update

    Apple has announced an important change to the Certification Authority (CA) for Apple Push Notification service (APNs). The update to APNs server certificates will take effect in the sandbox environment on January 20, 2025, and in the production environment on February 24, 2025.

    To ensure uninterrupted push notification services, developers must update their application’s Trust Store to include the new SHA-2 Root: USERTrust RSA Certification Authority certificate before the respective cut-off dates.

    If You Use Firebase or Microsoft Azure Notification Service

    If your application uses Firebase Cloud Messaging (FCM) or Microsoft Azure Notification Hubs, you probably do not need to take any action. These services manage push notifications on behalf of your application, handling all necessary certificate updates internally. Google and Microsoft will ensure their backend services are updated with the new APNs root certificate, so you won’t need to manually update your Trust Store unless you have custom implementations that directly communicate with APNs.

    If you directly connect to Apple’s APNs with Windows Servers

    Then read on.
    It is essential that all Windows servers communicating with APNs trust both the old and new certificates to avoid any disruptions. Below are the steps to correctly import the new root certificate into your Windows servers.

    Steps to Update the APNs Certificate on Windows Servers

    Step 1: Download the New Root Certificate

    1. Open your web browser and navigate to the official certificate provider’s page: Sectigo Intermediate Certificates
    2. Locate and download the USERTrust RSA Certification Authority root certificate in .cer or .crt format.

    Step 2: Open Certificate Manager

    1. Press Win + R to open the Run dialog.
    2. Type certmgr.msc and press Enter.
    3. The Certificate Manager will open, allowing you to manage trusted certificates.

    Step 3: Import the New Root Certificate

    1. In Certificate Manager, expand the Trusted Root Certification Authorities folder.
    2. Right-click on the Certificates subfolder.
    3. Select All Tasks > Import.
    4. The Certificate Import Wizard will appear. Click Next.
    5. Browse to the location where you saved the downloaded certificate and select it.
    6. Click Next and follow the prompts to complete the import process.

    Step 4: Verify the Import

    1. After the import is complete, navigate to Trusted Root Certification Authorities > Certificates.
    2. Confirm that the USERTrust RSA Certification Authority certificate is listed.

    Step 5: Update Group Policy (for Domain-Joined Computers)

    If your Windows servers are part of a domain, updating the Group Policy will ensure that all connected machines receive the updated certificate.

    1. Open Group Policy Management Console.
    2. Create or edit an existing Group Policy Object (GPO).
    3. Navigate to Computer Configuration > Windows Settings > Security Settings > Public Key Policies.
    4. Right-click on Trusted Root Certification Authorities and select Import.
    5. Follow the wizard to import the new root certificate.
    6. Apply the GPO to all required machines and restart them if necessary.

    Sources

    https://developer.apple.com/news/?id=09za8wzy

    https://developer.apple.com/news/upcoming-requirements/?id=01202025a

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

    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>
    
  • Firebase Admin SDK C#: iOS-en nincs hang a PushNotification megérkezésekor.

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

    Androiddal ellentétben, iOS-en, amennyiben nem határozzuk meg expliciten azt, hogy a készülék hangot játsszon le a RemoteNotification megérkezésekor, a készülék némán kézbesíti az értesítést.

    Amennyiben a C#-os FirebaseAdmin SDK implementációt használjuk a PushNotificationok kiküldéséhez, platformspecifikus mezőket kell használni a Notification-ban.

    Forrás: https://firebase.google.com/docs/cloud-messaging/send-message#when-to-use-common-fields

    A hangot az apns objektumban kell meghatározni az iOS platform számára. C# implementációbanban a Notification osztály tartalmaz egy APNs obejktumot, amelynek a következők szerint kell értéket adni:

            var Message = new FirebaseAdmin.Messaging.Message()
                {
                    Notification = new FirebaseAdmin.Messaging.Notification
                    {
                        Title = title,
                        Body = message,            
                    },
                    Token = token,
                    Data = data,
                    Apns = new FirebaseAdmin.Messaging.ApnsConfig()
                    {
                        Aps = new FirebaseAdmin.Messaging.Aps()
                        {
                            Sound = "default"
                        }
                    }
                };
    

    A default paraméter az értesítések alapértelmezett hangját szólaltatja meg a telefonnal. Amennyiben saját hangot szeretnénk lejátszani, azt is itt kell meghatározni.