Data messages broken with the new Firebase update

pelisterpelister USMember ✭✭

I upgraded Firebase packages to 2.0.0 yesterday. There are some API changes that are currently not reflected to the documentation here.

As per the compiler errors and warnings, I replaced InstanceId.Notifications.ObserveTokenRefresh(this.OnTokenRefresh) with the new delegate method called DidRefreshRegistrationToken. There are no prblems with getting a Firebase token.

I also replaced Messaging.SharedInstance.Connect(this.OnConnected) with Messaging.SharedInstance.ShouldEstablishDirectChannel = true. And now data messages are broken, the app cannot receive any, ApplicationReceivedRemoteMessage is never called.

Can the Xamarin guys provide a documentation following such updates?

Answers

  • pelisterpelister USMember ✭✭

    I'm sorry I didn't mention that the data message problem is on iOS 11 only.

    Has anyone tried FCM on iOS11 yet? what are your results?

  • KimJensenKimJensen USMember ✭✭

    I got the latest release and I now get those error:

    IMessagingDelegate 'AppDelegate' does not implement interface member 'ImessagingDelegate.DidRefreshRegistrationToken(Messing,string)'

    Messaging.SharedInstance.RemoteMessageDelegate = this;
    Messaging.RemoteMessageDelegate is obsolete: Use Delegate property instead'

    Firebase.Analytics.App.Configure();
    'App' does not exist in namespace 'Firebase.Analytics'

    Have the same code and the same Xamarin.Firebase.Messaging NuGet package on the Mac with no errors.

    You changed InstanceId.Notifications.ObserveTokenRefresh ((sender, e) to DidRefreshRegistrationToken
    How did you replace it because I can't find DidRefreshRegistrationToken?

  • KimJensenKimJensen USMember ✭✭

    I found that the Firebase.Analytics.App.Configure(); is now Firebase.Core.App.Configure();

  • pelisterpelister USMember ✭✭

    Hi Kim,
    I made all of my changes following the compiler warnings and errors. The compiler warns that InstanceId.Notifications.ObserveTokenRefresh was obsolete and that the new delegate method should be used.

    After such a breaking change, xamarin still has not updated the official documentation as of today.

  • KimJensenKimJensen USMember ✭✭

    I was able to change all but this one.
    IMessagingDelegate 'AppDelegate' does not implement interface member 'ImessagingDelegate.DidRefreshRegistrationToken(Messing,string)'

    Right now my code looks like this:
    InstanceId.Notifications.ObserveTokenRefresh ((sender, e)=>

  • pelisterpelister USMember ✭✭

    Actually just add the method with the correct signature, and you should be good to go:

    public void DidRefreshRegistrationToken(Messaging, string)

    I wish you can receive data messages.

  • JannieTheunissenJannieTheunissen GBMember ✭✭
    edited October 2017

    I can receive data messages on on this undocumented method:

    [Export("messaging:didReceiveMessage:")] 
    public void DidReceiveMessage(Firebase.CloudMessaging.Messaging messaging, Firebase.CloudMessaging.RemoteMessage remoteMessage)
    { 
         Console.WriteLine(remoteMessage.AppData);
    }
    
  • @pelister Can you please help me with the exact method that you called?

    Did you removed the "InstanceId.Notifications.ObserveTokenRefresh" and do you have to call the DidRefreshRegistrationToken from FinishedLaunching method?

  • pelisterpelister USMember ✭✭

    @ASHISHKUMAR.8068 yes I removed InstanceId.Notifications.ObserveTokenRefresh.
    DidRefreshRegistrationToken is actually a method from IMessagingDelegate interface, you can't invoke it by yourself. you
    should implement the interface.

  • ASHISHKUMAR.8068ASHISHKUMAR.8068 USMember ✭✭
    edited November 2017

    @pelister Can you share your piece of code , because my debugger never hits DidRefreshRegistrationToken.This is what I have done.

    [Export("messaging:didRefreshRegistrationToken:")]
    public void DidRefreshRegistrationToken(Messaging mess, string token)
    {
    Console.WriteLine(token);
    }
    and I am using "Xamarin.Firebase.iOS.CloudMessaging" version="2.0.4"

  • @pelister The link is for AppDelegate https://pastebin.mozilla.org/9072761

  • TomAugaTomAuga USMember

    @ASHISHKUMAR.8068 I have tried your example on an iOS 11.1 simulator using CloudMessaging v2.0.4 and Messaging.SharedInstance.Connect() gets the following error:

    The operation couldn’t be completed. (com.google.fcm error 501.)
    

    Do you have any idea why this is happening?

    I haven't found an example that uses the 2.0.4 new (non-obsolete) methods and have been fighting this on iOS for a few weeks now. So figured I would first get it working using the obsolete methods (as in your example) first. Any help would be greatly appreciated.

  • BrentSaferBrentSafer USMember ✭✭

    @TomAuga said:
    @ASHISHKUMAR.8068 I have tried your example on an iOS 11.1 simulator using CloudMessaging v2.0.4 and Messaging.SharedInstance.Connect() gets the following error:

    The operation couldn’t be completed. (com.google.fcm error 501.)

    Do you have any idea why this is happening?

    I haven't found an example that uses the 2.0.4 new (non-obsolete) methods and have been fighting this on iOS for a few weeks now. So figured I would first get it working using the obsolete methods (as in your example) first. Any help would be greatly appreciated.

    Did you resolve your 501? I'm receiving this on iOS 11, works fine on version 9. I've spent many hours trying to find a solution. Appreciate anything you can offer.

  • TomAugaTomAuga USMember
    edited January 13

    @BrentSafer I did finally figure this out but couldn't find this post to update it. It seems that for iOS, CloudMessaging does not work in the simulator. Note that CloudMessaging works find on the Android emulators shipped with Visual Studio 2017.

    I ended up buying an iPhone 6 and tested my code on it and it worked as advertised. I don't remember where I found a note saying that CM doesn't work on the simulator but it wasn't in the Apple documentation.

  • BrentSaferBrentSafer USMember ✭✭

    @TomAuga Thanks for the response. I guess I'll have to find a newer iphone to test. Strange it worked on Iphone 5s simuator fine in version 9.3.

    These things make me nuts in Xamarin.

  • SmartManSmartMan INMember ✭✭

    anyone achieve this for ios 11 ??

  • BrentSaferBrentSafer USMember ✭✭

    I'm getting real device, because IOS simulator doesn't support push notifications. You can get the notofications to work, just not push notifications when app is in the background.

  • SmartManSmartMan INMember ✭✭

    can you share your code to implement this in Appdeligate.cs?

  • BrentSaferBrentSafer USMember ✭✭

    I used the tutorial and instructions from here.
    https://components.xamarin.com/gettingstarted/firebaseioscloudmessaging

    Take a look at this plugin. Much easier to implement and setup for forms already.
    https://github.com/CrossGeeks/FirebasePushNotificationPlugin

Sign In or Register to comment.