public MainPage() { InitializeComponent(); pushAPIs = DependencyService.Get <IPushAPIs>(); notification = new ObservableCollection <Notification>(); // Data binding to UI MyListView.ItemsSource = notification; // Process when notification is received App.NotificationReceivedListener += (s, e) => { if (e is NotificationReceivedEventArgs) { // parsing action and alertMessage from received message string[] val = e.message.Split('&'); string msg1 = ""; string msg2 = ""; foreach (string temp in val) { if (temp.Contains("action")) { msg1 = temp.Substring(temp.IndexOf("=") + 1); } if (temp.Contains("alertMessage")) { msg2 = temp.Substring(temp.IndexOf("=") + 1); } } Console.WriteLine("Notification Received : " + e.message); //Add your code here when push messages arrive // Example UI : add notification to UI // "Type : ALERT / Message : 1st Push" // "20171019 11:20:22 PM" notification.Add(new Notification("Type : " + msg1 + " / Message : " + msg2, e.receiveTime.ToString())); } }; // Process when registration state is changed App.RegistrationStateChangedListener += (s, e) => { if (e is RegistrationStateChangedListener) { Console.WriteLine("State Changed : [" + e.state + "]"); // Add your code here when registration state is changed } }; }
public App() { InitializeComponent(); MainPage = new NavigationPage(new MainPage()); pushAPIs = DependencyService.Get <IPushAPIs>(); }