21.9 C
Canberra
Tuesday, February 10, 2026

Badge rely is just not incrementing in Push Notification utilizing OneSignal in iOS MAUI app


I’ve developed MAUI app utilizing Visible Studio 2022 v 17.14.16 and .NET 9. I’ve already developed Android app and it’s on Google Play Retailer.

Now I’m creating iOS MAUI app so I’ve enabled iOS as a goal Platform. Goal .Web runtime as .Web 9 and Minimal goal iOS framework is 16.0.

Badge rely is just not incrementing in Push Notification utilizing OneSignal in iOS MAUI app

I’ve carried out Push Notification performance by including Notification Service Extension (NSE) Venture in Visible Studio Home windows.

For each Primary app and NSE, I’ve created App Id. For Primary App, App Id I’ve enabled Push Notification and App Group capabilities and for NSE undertaking I’ve enabled App Group functionality in Apple developer portal. I’ve created App group (group.com.firm.id.title) and configured to App Id of each Primary App and NSE undertaking.

In App.xaml.cs file, I’ve initialized OneSignal like beneath:

OneSignal.Initialize("OneSignal_App_Id");
OneSignal.Notifications.RequestPermissionAsync(true);

In Primary app’s Information.plist, I’ve added beneath keys for Push notification-

Primary app Information.plist

<?xml model="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist model="1.0">
<dict>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UIDeviceFamily</key>
<array>
    <integer>1</integer>
</array>
<key>UIRequiredDeviceCapabilities</key>
<array>
    <string>arm64</string>
</array>
<key>UISupportedInterfaceOrientations</key>
<array>
    <string>UIInterfaceOrientationPortrait</string>
    <string>UIInterfaceOrientationLandscapeLeft</string>
    <string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
    <string>UIInterfaceOrientationPortrait</string>
    <string>UIInterfaceOrientationPortraitUpsideDown</string>
    <string>UIInterfaceOrientationLandscapeLeft</string>
    <string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>XSAppIconAssets</key>
<string>Belongings.xcassets/appicon.appiconset</string>
<key>CFBundleShortVersionString</key>
<string>0.1</string>
<key>CFBundleVersion</key>
<string>1.0.0</string>
<key>CFBundleIdentifier</key>
<string>com.firm.id.title</string>
<key>CFBundleDisplayName</key>
<string>Cellular app</string>
<key>CFBundleName</key>
<string>Cellular app</string>
<key>MinimumOSVersion</key>
<string>16.0</string>
<key>NSCameraUsageDescription</key>
<string>We'd like digital camera entry to seize photos.</string>
<key>CFBundleURLTypes</key>
<array>
    <dict>
        <key>CFBundleURLSchemes</key>
    <array>
        <string>com.googleusercontent.apps.reverseClientId</string>
    </array>
        </dict>
</array>
<key>UIBackgroundModes</key>
<array>
    <string>fetch</string>
    <string>remote-notification</string>
</array>
<key>OneSignal_app_groups_key</key>
<string>group.com.firm.id.title.onesignal</string>

Primary app’s Entitlements.plist

<?xml model="1.0" encoding="utf-8" ?> 
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist model="1.0">
<dict>
<key>aps-environment</key>
<string>growth</string>
<key>com.apple.safety.application-groups</key>
<array>
    <string>group.com.firm.id.title.onesignal</string>
</array>

Primary App .csproj Configuration

<PropertyGroup>
  <TargetFrameworks>net9.0-android35.0;net9.0-ios18.0</TargetFrameworks>
  <OutputType>Exe</OutputType>
  <UseMaui>true</UseMaui>
  <SingleProject>true</SingleProject>
  <ImplicitUsings>allow</ImplicitUsings>
</PropertyGroup>
<SupportedOSPlatformVersion Situation="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">16.0</SupportedOSPlatformVersion>

<PropertyGroup Situation="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net9.0-ios18.0|AnyCPU'">
<DebugSymbols>true</DebugSymbols>
<Optimize>false</Optimize>
<MtouchLink>None</MtouchLink>
<CodesignEntitlements>PlatformsiOSEntitlements.plist</CodesignEntitlements>
</PropertyGroup>
<ItemGroup  Situation="'$(TargetFramework)' == 'net9.0-ios18.0'">
    <PackageReference Embody="OneSignalSDK.DotNet" Model="5.2.2" />
</ItemGroup>
<ItemGroup Situation="'$(TargetFramework)' == 'net9.0-ios18.0'">
  <ProjectReference Embody="..OneSignalNotificationServiceExtensionOneSignalNotificationServiceExtension.csproj">
      <IsAppExtension>true</IsAppExtension>
  </ProjectReference>
</ItemGroup>

NSE Information.plist

<?xml model="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist model="1.0">
<dict>
<key>CFBundleDisplayName</key>
<string>OneSignalNotificationServiceExtension</string>
<key>CFBundleName</key>
<string>OneSignalNotificationServiceExtension</string>
<key>CFBundleIdentifier</key>
<string>com.firm.id.title.OneSignalNotificationServiceExtension</string>
<key>CFBundlePackageType</key>
<string>XPC!</string>
<key>CFBundleShortVersionString</key>
<string>0.1</string>
<key>CFBundleVersion</key>
<string>1.0.0</string>
<key>NSExtension</key>
<dict>
    <key>NSExtensionPointIdentifier</key>
    <string>com.apple.usernotifications.service</string>
    <key>NSExtensionPrincipalClass</key>
    <string>NotificationService</string>
</dict>
<key>UIBackgroundModes</key>
<array>
    <string>remote-notification</string>
</array>
<key>MinimumOSVersion</key>
<string>16.0</string>
<key>OneSignal_app_groups_key</key>
<string>group.com.firm.id.title.onesignal</string>
</dict>
</plist>

NSE Entitlements.plist

<?xml model="1.0" encoding="utf-8" ?> 
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist model="1.0">
<dict>
<key>com.apple.safety.application-groups</key>
<array>
    <string>group.com.firm.id.title.onesignal</string>
</array>
</dict>
</plist>

NSE configuration

<Venture Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net9.0-ios18.0</TargetFramework>
<OutputType>Library</OutputType>
<Nullable>allow</Nullable>
<ImplicitUsings>true</ImplicitUsings>
<SupportedOSPlatformVersion>16.0</SupportedOSPlatformVersion>
<IsAppExtension>True</IsAppExtension>
<RuntimeIdentifier>ios-arm64</RuntimeIdentifier>
<ApplicationId>com.firm.id.title.OneSignalNotificationServiceExtension</ApplicationId>
</PropertyGroup>
<PropertyGroup Situation="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<CodesignEntitlements>Entitlements.plist</CodesignEntitlements>
</PropertyGroup>
<PropertyGroup Situation="'$(Configuration)|$(Platform)'=='Launch|AnyCPU'">
<CodesignEntitlements>Entitlements.plist</CodesignEntitlements>
</PropertyGroup>
<ItemGroup>
<PackageReference Embody="OneSignalSDK.DotNet" Model="5.2.2" />
</ItemGroup>
</Venture>

NotificationServiceClass

utilizing System;
utilizing Basis;
utilizing OneSignalSDK.DotNet;
utilizing OneSignalSDK.DotNet.iOS;
utilizing UIKit;
utilizing UserNotifications;

namespace OneSignalNotificationServiceExtension
{
[Register("NotificationService")]
public class NotificationService : UNNotificationServiceExtension
{
    Motion<UNNotificationContent> ContentHandler { get; set; }
    UNMutableNotificationContent BestAttemptContent { get; set; }
    UNNotificationRequest ReceivedRequest { get; set; }
    protected NotificationService(IntPtr deal with) : base(deal with)
    {
        // Notice: this .ctor mustn't include any initialization logic,
        // it solely exists in order that the OS can instantiate an occasion of this class.
    }

    public override void DidReceiveNotificationRequest(UNNotificationRequest request, Motion<UNNotificationContent> contentHandler)
    {
        Console.WriteLine("DidReceive**********************");
        ReceivedRequest = request;
        ContentHandler = contentHandler;
        BestAttemptContent = (UNMutableNotificationContent)request.Content material.MutableCopy();

        NotificationServiceExtension.DidReceiveNotificationExtensionRequest(request, BestAttemptContent, contentHandler);
    }

    public override void TimeWillExpire()
    {
        NotificationServiceExtension.ServiceExtensionTimeWillExpireRequest(ReceivedRequest, BestAttemptContent);

        ContentHandler(BestAttemptContent);
    }

}
}

Under is my payload of notification I’m passing by way of API:

var notification = new Notification(appId: _AppId)
{
 Contents = new StringMap(en: message),
 IncludeExternalUserIds = externalUserId,
 IosBadgeType = "Improve",
 IosBadgeCount = 1,
 MutableContent = true 
};

In each Primary app and NSE undertaking properties iOS Bundle signing, I’ve chosen Handbook Provisioning and chosen Signing Identification and Provisioning Profile resp. for Primary App and NSE

I’ve paired Visible Studio Home windows with Mac. I get Push notifications on my app. On Notification Middle it’s exhibiting right rely however difficulty is on app icon badge rely is just not rising, it’s caught at 1 solely.

I feel NSE is just not working as a result of if I add any prefix to physique in DidReceiveNotification technique, then it isn’t exhibiting.

I get beneath error:

INFO: An error occurred whereas forwarding HotReload native tunnel: System.IO.IOException: USB join timeout (ENODATA), seemingly as a result of the app did not launch. Please assessment machine logs and/or crash experiences for extra info.
   at Xamarin.MacDev.AggregateAsyncResult.CheckError(Boolean cancelled)
   at Xamarin.MacDev.IPhoneDevice.EndConnectStream(IAsyncResult end result)
   at System.Threading.Duties.TaskFactory`1.FromAsyncCoreLogic(IAsyncResult iar, Func`2 endFunction, Motion`1 endAction, Job`1 promise, Boolean requiresSynchronization)
--- Finish of stack hint from earlier location ---
   at Xamarin.Messaging.IDB.IPhoneUsbLocalTunnelConnection.StartLocalTunnelAsync()
   at Xamarin.Messaging.IDB.LaunchAppMessageHandler.ForwardLocalTunnelsAsync(LaunchAppMessage, IPhoneDevice)
ERROR: [iOS HotReload] Failed to hook up with "iPhone" over USB on port 11000.

For this error- I’ve disabled / unchecked .NET Sizzling Reload and uncheck Allow Sizzling Reload however identical error persists.

Is there something I’m lacking due to which badge rely is just not rising? If there isn’t any communication occurs between Primary app and NSE then what must be accomplished?

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

[td_block_social_counter facebook="tagdiv" twitter="tagdivofficial" youtube="tagdiv" style="style8 td-social-boxed td-social-font-icons" tdc_css="eyJhbGwiOnsibWFyZ2luLWJvdHRvbSI6IjM4IiwiZGlzcGxheSI6IiJ9LCJwb3J0cmFpdCI6eyJtYXJnaW4tYm90dG9tIjoiMzAiLCJkaXNwbGF5IjoiIn0sInBvcnRyYWl0X21heF93aWR0aCI6MTAxOCwicG9ydHJhaXRfbWluX3dpZHRoIjo3Njh9" custom_title="Stay Connected" block_template_id="td_block_template_8" f_header_font_family="712" f_header_font_transform="uppercase" f_header_font_weight="500" f_header_font_size="17" border_color="#dd3333"]
- Advertisement -spot_img

Latest Articles