Skip to content

Receive GetSocial Notifications on Unity

Notification Center with GetSocial

GetSocial provides a data API to implement notification center, similar to what Facebook has, inside your application. All notifications received via API will also generate an associated push notification.

GetSocial Notification Center UI

Let your users receive and interact with GetSocial Notifications in minutes, not days with prebuilt Notification Center UI.

Prerequisite

Receive Notifications

To be sure your users didn’t miss any important (or not) notifications, you can query GetSocial notifications and show it to your user inside the app. Or send it once again as local notification. Or handle it in any other convenience method.

Query

You have two types of queries: NotificationQuery and NotificationsCountQuery to get notifications list and notifications count respectively.

Notification can differ by a read status - be read or unread. Also each notification has type, it is one of Notification.NotificationTypes constants.

To query notifications by status, use WithStatuses(params string[] statuses) factory method. You can pass one or few statuses from NotificationStatus constants. Use WithAllStatuses() to query notifications with any status.

By default notifications of all types are queries. Also you can explicitly call OfAllTypes() to be sure that all types are queries. To specify a list of types you’re interested in call method OfTypes(Notification.NotificationTypes... types) and pass one or few types you want to query.

Notifications Count

To get the count of notifications use GetSocial.User.GetNotificationsCount(query, onSuccess, onFailure) method. For example, to get a number of all unread notifications for current user:

1
2
NotificationsCountQuery query = NotificationsCountQuery.WithStatuses(NotificationStatus.Unread).OfAllTypes();
GetSocial.User.GetNotificationsCount(query, count => Debug.Log("Notifications count is" + count), error => Debug.LogError("Failed to get notifications count: " + error));

Notifications List

Similar to notifications count you can fetch a list of notifications using GetSocial.User.getNotifications(query, callback) mehtod:

1
2
NotificationsQuery query = NotificationsQuery.WithStatuses(NotificationStatus.Unread).OfAllTypes();
GetSocial.User.GetNotifications(query, notifications => ShowNotifications(notifications), error => Debug.LogError("Failed to get notifications: " + error));

Notifications Status

Read and Unread

All the notifications that are sent to a user are unread. The only exception is notifications that was clicked by a user - such becomes read automatically.

If you want to set notification read or unread use GetSocial.User.SetNotificationsStatus(notificationIds, newStatus, onSuccess, onFailure) method:

1
2
3
4
List<Notification> notificationsToBeRead = ...;
var notificationIds = notificationsToBeRead.ConvertAll(notification => notification.Id);
var newStatus = NotificationStatus.Read;
GetSocial.User.SetNotificationsStatus(notificationIds, newStatus, () => Debug.Log("Successfully changed notification status"), error => Debug.LogError("Failed to change notifications: " + error));

You can mark just one notification using new List<string> { notification.Id }.

Consumed and Ignored

If your notification is kind of “consumable” - e.g. friend request, pending action or whatever it could be(check some possible usecase) - you may want to mark it as “consumed” by user, so it won’t appear in the list of read/unread notifications. For this there is NotificationStatus.Consumed status. If user wants to ignore it, e.g. decline friends request, set it to NotificationStatus.Ignored.

Next Steps

Give us your feedback! Was this article helpful?

😀 🙁