Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"error": "InvalidRegistration" while sending push notifications

I am implementing FCM push notifications using FirebasePushNotificationPlugin in Xamarin.Forms. In iOS project, in AppDelegate when RegisteredForRemoteNotifications method calling deviceToken generating but when I am sending notification for generated token by Postman I am getting error.

{ "multicast_id": 8631208504861228784, "success": 0, "failure": 1, "canonical_ids": 0, "results": [ { "error": "InvalidRegistration" } ] }

This is the code I have on AppDelegate got from here:

public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
    global::Xamarin.Forms.Forms.Init();
    LoadApplication(new App());

    FirebasePushNotificationManager.Initialize(options, new NotificationUserCategory[]
    {
        new NotificationUserCategory("message",new List<NotificationUserAction> {
            new NotificationUserAction("Reply","Reply",NotificationActionType.Foreground)
        }),
        new NotificationUserCategory("request",new List<NotificationUserAction> {
            new NotificationUserAction("Accept","Accept"),
            new NotificationUserAction("Reject","Reject",NotificationActionType.Destructive)
        })
    });

    return base.FinishedLaunching(app, options);
}

public override void RegisteredForRemoteNotifications(UIApplication application, NSData deviceToken)
{
    FirebasePushNotificationManager.DidRegisterRemoteNotifications(deviceToken);
    Console.WriteLine("Token- - - :  "+deviceToken);
}

public override void FailedToRegisterForRemoteNotifications(UIApplication application, NSError error)
{
    FirebasePushNotificationManager.RemoteNotificationRegistrationFailed(error);
}

public override void DidReceiveRemoteNotification(UIApplication application, NSDictionary userInfo, Action<UIBackgroundFetchResult> completionHandler)
{
    FirebasePushNotificationManager.DidReceiveMessage(userInfo);
    System.Console.WriteLine(userInfo);
    completionHandler(UIBackgroundFetchResult.NewData);
}

data object in Postman when sending sample notification

{ 
 "to":"79f64b43339859a329a935f7a3e417ecc1599fbb5d6935afbooa3b4291c07fa7", 
 "notification" : {
 "body" : "New task",
 "content_available" : true,
 "priority" : "high",
 "color":"Page1",
 "title":"Announcement"
 },
 "data" : {
 "color":"Page1",
 "title":"title",
 "content_available" : true,
 "body" : "New Announcement ad"

}
}

Body of Postman

enter image description here

These are the Provisioning profiles setting from Visual Studio

enter image description here

How can I solve this issue?

like image 288
R15 Avatar asked Apr 09 '19 14:04

R15


1 Answers

I'm not familiar with Xamarin. But I worked with FCM a lot.

I think you are getting wrong token. Using deviceToken won't work with push notification from FCM. I did a search and maybe you have to get it from

var fcmToken = FirebaseInstanceId.Instance.Token;

More detail: https://docs.microsoft.com/en-us/xamarin/android/data-cloud/google-messaging/remote-notifications-with-fcm?tabs=macos

like image 58
tuledev Avatar answered Oct 21 '22 06:10

tuledev