Remote messages from FCM cloud messaging not been recieved by IOS

Richard Wilde 1 Reputation point
2021-03-23T11:18:20.293+00:00

Hi, I have been banging my head for a week now trying to get FCM to work on IOS (I have it working on Android)

To summarize, I have

  1. Managed to get a FCM token back when the app starts
  2. Downloaded GoogleService-info.plist and added it as a bundled resource
  3. Enabled push notifications in entitlements.plist
  4. Enable remote notifications for capabilites in info.plist
  5. In Firebase set up the APNS using "APN auth key"

The app starts (on phone!) asks me alow notifications, connects to Firebase and gets back a token. All of this seems to work fine. I can also subscribe to a topic e.g. news

However when sending a message via FCM or Postman it says "success" e.g.

{  
    "multicast_id": 4735234432799962226,  
    "success": 1,  
    "failure": 0,  
    "canonical_ids": 0,  
    "results": [  
        {  
            "message_id": "0:1616496033820393%da341eddda341edd"  
        }  
    ]  
}  

But IOS does not log or show any notifications. No break points are hit on my code. I just cant fathom it out.

I am sure its simple and missing a simple step.

I am using the following packages

80691-1.png

My code looks like this now, albeit I have hacked around for days

    [Register("AppDelegate")]  
    public partial class AppDelegate :  
        global::Xamarin.Forms.Platform.iOS.FormsApplicationDelegate,  
        IUNUserNotificationCenterDelegate,  
        IMessagingDelegate  
    {  
        public override bool FinishedLaunching(UIApplication app, NSDictionary options)  
        {  
            Xamarin.Forms.Forms.Init();  
            Syncfusion.SfGauge.XForms.iOS.SfGaugeRenderer.Init();  
  
            // Register your app for remote notifications.  
            if (UIDevice.CurrentDevice.CheckSystemVersion(10, 0))  
            {  
                // For iOS 10 display notification (sent via APNS)  
                UNUserNotificationCenter.Current.Delegate = this;  
  
                var authOptions = UNAuthorizationOptions.Alert | UNAuthorizationOptions.Badge | UNAuthorizationOptions.Sound;  
                UNUserNotificationCenter.Current.RequestAuthorization(authOptions, (granted, error) =>  
                {  
                    Log.Warning(nameof(FinishedLaunching), $"Granted: {granted}");  
                });  
            }  
            else  
            {  
                // iOS 9 or before  
                var allNotificationTypes = UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound;  
                var settings = UIUserNotificationSettings.GetSettingsForTypes(allNotificationTypes, null);  
                UIApplication.SharedApplication.RegisterUserNotificationSettings(settings);  
            }  
  
            Firebase.Core.App.Configure();  
            Messaging.SharedInstance.Delegate = this;  
  
            LoadApplication(new App());  
  
            UIApplication.SharedApplication.RegisterForRemoteNotifications();  
            InstanceId.SharedInstance.GetInstanceId(InstanceIdResultHandler);  
  
  
            return base.FinishedLaunching(app, options);  
        }  
  
        private void InstanceIdResultHandler(InstanceIdResult result, NSError error)  
        {  
            if (error != null)  
            {  
                return;  
            }  
            debugAlert("(1) Got Token", result.Token);  
        }  
  
        [Export("messaging:didReceiveRegistrationToken:")]  
        public void DidReceiveRegistrationToken(Messaging messaging, string fcmToken)  
        {  
            // Monitor token generation: To be notified whenever the token is updated.  
            debugAlert("(2) Got Token", fcmToken);  
            AppState.FcmToken = fcmToken;  
        }  
  
        public override void DidReceiveRemoteNotification(UIApplication application, NSDictionary userInfo, Action<UIBackgroundFetchResult> completionHandler)  
        {  
            debugAlert("(3) Got remote notification", userInfo.Description);  
  
            // Handle Notification messages in the background and foreground.  
            // Handle Data messages for iOS 9 and below.  
  
            // If you are receiving a notification message while your app is in the background,  
            // this callback will not be fired till the user taps on the notification launching the application.  
            // TODO: Handle data of notification  
  
            // With swizzling disabled you must let Messaging know about the message, for Analytics  
            Messaging.SharedInstance.AppDidReceiveMessage(userInfo);  
  
            HandleMessage(userInfo);  
  
            // Print full message.  
            //Log.Warning (nameof (DidReceiveRemoteNotification), userInfo.Description);  
  
            completionHandler(UIBackgroundFetchResult.NewData);  
        }  
  
        [Export("messaging:didReceiveMessage:")]  
        public void DidReceiveMessage(Messaging messaging, RemoteMessage remoteMessage)  
        {  
            debugAlert("handling message", "TODO");  
            // Handle Data messages for iOS 10 and above.  
            HandleMessage(remoteMessage.AppData);  
        }  
  
        private void HandleMessage(NSDictionary message)  
        {  
            //TODO  
        }  
  
        private void debugAlert(string title, string message)  
        {  
            var avAlert = new UIAlertView(title ?? "Unknown title", message ?? "Unknown description", null, "OK", null);  
            avAlert.Show();  
        }  
    }  
Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,371 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Eric DellOro 1 Reputation point
    2021-04-23T01:09:15.66+00:00

    What version of iOS is the physical device using ???


  2. Prince Tiwari 1 Reputation point
    2021-10-06T09:52:20.253+00:00

    Hi @Eric DellOro did you resolve the issue?

    i am facing the same issue

    0 comments No comments

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.