Implementing Critical Alerts in Xamarin.iOS (with AppCenter and FCM)

FloGey 1 Reputation point
2021-06-22T08:53:46.48+00:00

Hi im trying to implement iOS Critical Alerts in my Xamarin.Forms App. For Push iam using Firebase Cloud Messageing, Compilation and Distribution is done via MS Appcenter. I thing ive reproduced all necessary steps from https://learn.microsoft.com/en-us/xamarin/ios/platform/introduction-to-ios12/notifications/critical-alerts but after first start of the App i do not receive the Request for Critical alerts prompt.
Here what i have done so far:

  1. Requested the critical alerts entitlement from apple and got it approved.
  2. Created a fresh provisioning profile with the pritical alerts entitlement.
  3. Added the provisioning profile under build signing of the Build Configuration in Appcenter.
  4. Added the critical alerts entitlement in the Entitlement.plist <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    <plist version="1.0">
    <dict>
    <key>aps-environment</key>
    <string>development</string>
    <key>com.apple.security.application-groups</key>
    <array>
    <string>group.com.my.App</string>
    </array>
    <key>com.apple.developer.usernotifications.critical-alerts</key>
    <true/>
    </dict>
    </plist>
  5. Edited the bundle signing to use Entitlements.plist

108039-unbenannt.png

  1. Added the Critical Alerts Permission Request in the FinishedLaunching Method of the AppDelegate.cs. public override bool FinishedLaunching(UIApplication app, NSDictionary options)
    {
    Forms.Init(); …
               Firebase.Core.App.Configure();  
            // Register your app for remote notifications.  
            if (UIDevice.CurrentDevice.CheckSystemVersion(12, 0))  
            {  
                // iOS 12 or later  
                var authOptions = UNAuthorizationOptions.Alert | UNAuthorizationOptions.Badge | UNAuthorizationOptions.Sound | UNAuthorizationOptions.CriticalAlert;  
                UNUserNotificationCenter.Current.RequestAuthorization(authOptions, (granted, error) =>  
                {  
                });  
    
                // For iOS 10 display notification (sent via APNS)  
                UNUserNotificationCenter.Current.Delegate = this;  
            }  
            else if (UIDevice.CurrentDevice.CheckSystemVersion(10, 0))  
            {  
                // iOS 10 or later  
                var authOptions = UNAuthorizationOptions.Alert | UNAuthorizationOptions.Badge | UNAuthorizationOptions.Sound;  
                UNUserNotificationCenter.Current.RequestAuthorization(authOptions, (granted, error) =>  
                {  
                });  
    
                // For iOS 10 display notification (sent via APNS)  
                UNUserNotificationCenter.Current.Delegate = this;  
            }  
            else  
            {  
                // iOS 9 or before  
                var allNotificationTypes = UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound;  
                var settings = UIUserNotificationSettings.GetSettingsForTypes(allNotificationTypes, null);  
                UIApplication.SharedApplication.RegisterUserNotificationSettings(settings);  
            }  
    
            Messaging.SharedInstance.Delegate = this;  
            UIApplication.SharedApplication.RegisterForRemoteNotifications();  
            return base.FinishedLaunching(app, options);  
        }  
    

After building and distributing the app to testflight i installed it on a Iphone with iOS 14.6. After starting the App i only get a normal Pushnotification permission request popup.

What am i missing here? Help would be much appreciated.

Developer technologies | .NET | Xamarin
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.