Message Center
Airship Message Center is a place in your app where you can display persistent rich messages, including HTML, video, etc. The messages are hosted by Airship, and are typically displayed in standard inbox-style within your app.
The default message center can be displayed at any time
Airship.Instance.DisplayMessageCenter()
To display the inbox message
Airship.Instance.DisplayMessage("message-id")
To get the message count
var count = Airship.Instance.MessageCenterCount;
To get the unread message count
var count = Airship.Instance.MessageCenterUnreadCount;
To mark the message as read
Airship.Instance.MarkMessageRead("message-id")
To delete the message
Airship.Instance.DeleteMessage("message-id")
Getting inbox messages
var messages = Airship.Instance.InboxMessages;
An example of a Message Center inbox
/**
* Sample Xamarin Forms App
*
* MessageCenterScreen: Contains the list of messages.
*/
using System;
using System.Collections.Generic;
using Xamarin.Forms;
using UrbanAirship.NETStandard;
using UrbanAirship.NETStandard.MessageCenter;
namespace SampleApp
{
public partial class MessageCenterViewController : ContentPage
{
public MessageCenterViewController()
{
InitializeComponent();
}
protected override void OnAppearing()
{
var messages = Airship.Instance.InboxMessages;
listView.ItemsSource = messages;
}
void listView_ItemSelected(System.Object sender, Xamarin.Forms.SelectedItemChangedEventArgs e)
{
var message = e.SelectedItem as Message;
var messagePage = new MessagePage();
messagePage.MessageId = message.MessageId;
messagePage.LoadStarted += onLoadStarted;
messagePage.Loaded += onLoaded;
messagePage.Closed += onClosed;
messagePage.LoadFailed += onLoadFailed;
Navigation.PushAsync(messagePage);
}
private void onLoadStarted(object sender, MessageLoadStartedEventArgs e)
{
Console.WriteLine("onLoadStarted was reached.");
}
private void onLoaded(object sender, MessageLoadedEventArgs e)
{
Console.WriteLine("onLoaded was reached.");
}
private void onClosed(object sender, MessageClosedEventArgs e)
{
Console.WriteLine("onClosed was reached.");
}
private void onLoadFailed(object sender, MessageLoadFailedEventArgs e)
{
Console.WriteLine("onLoadFailed was reached.");
}
}
}
/**
* Sample Xamarin Forms App
*
* MessageCenterScreen: Contains the list of messages.
*/
<?xml version="1.0" encoding="UTF-8"?>
<ContentPage
Title="{x:Static resources:AppResources.message_center_title}"
xmlns:resources="clr-namespace:SampleApp"
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="SampleApp.MessageCenterViewController">
<ContentPage.Content>
<ListView x:Name="listView" ItemSelected="listView_ItemSelected" RowHeight="90">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout Orientation="Horizontal" Padding="20">
<BoxView x:Name="isReadIndicator"
CornerRadius="7"
WidthRequest="14" HeightRequest="14">
<BoxView.Triggers>
<DataTrigger TargetType="BoxView" Binding="{Binding Unread}" Value="true">
<Setter Property="BackgroundColor" Value="Green" />
</DataTrigger>
<DataTrigger TargetType="BoxView" Binding="{Binding Unread}" Value="false">
<Setter Property="BackgroundColor" Value="Blue" />
</DataTrigger>
</BoxView.Triggers>
</BoxView>
<StackLayout>
<Label Text="{Binding Title}"/>
<Label Text="{Binding SentDate, StringFormat='{0:MMMM dd, yyyy, hh:mm}'}" TextColor="Gray"/>
</StackLayout>
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</ContentPage.Content>
</ContentPage>
Look at our sample app for more details.
Feedback
Was this page helpful?
Thank you
Thanks for your feedback!
Tell Us MoreThank you
We will try harder!
Tell Us MoreCategories