What version of iOS is the physical device using ???
Remote messages from FCM cloud messaging not been recieved by IOS
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
- Managed to get a FCM token back when the app starts
- Downloaded GoogleService-info.plist and added it as a bundled resource
- Enabled push notifications in entitlements.plist
- Enable remote notifications for capabilites in info.plist
- 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
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();
}
}
2 answers
Sort by: Most helpful
-
-
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