I am creating a cross-platform mobile app with Xamarin, and I am trying to use MessagingCenter to send a message when an event occurs. The event should be handled differently depending on if the phone is running iOS or Android.
I am able to send a message from my PCL to MainActivity.cs (in Droid).
Here's how I'm sending a message:
MessagingCenter.Send<object, string>(this, "ChangeVenue", "Zw325nfe2");
And here is how I am subscribing to that message for Android in MainActivity.cs:
MessagingCenter.Subscribe<object, string>(this, "ChangeVenue", (sender, msg) =>
{
//stuff
});
I am not able, however, to do a the same thing for iOS. I think I just don't know where to add a subscription. Main.cs doesn't work because "this" cannot be referenced from a static context. I'm thinking AppDelegate.cs may be a good place to subscribe to the message, but putting it in FinishedLaunching() doesn't make sense.
How do you subscribe to messages using MessagingCenter for iOS builds?