API
CBSNotificationModule.GetNotificationList - Get all notifications for profile
using CBS;
using CBS.Models;
using UnityEngine;
public class NotificationExample : MonoBehaviour
{
private INotificationCenter NotificationCenter { get; set; }
private void Start()
{
NotificationCenter = CBSModule.Get<CBSNotificationModule>();
var request = new CBSGetNotificationsRequest
{
Request = NotificationRequest.PROFILE,
SpecificCategory = string.Empty
};
NotificationCenter.GetNotificationList(request, OnGet);
}
private void OnGet(CBSGetNotificationsResult result)
{
if (result.IsSuccess)
{
var notificationList = result.Notifications;
foreach (var notification in notificationList)
{
var id = notification.ID;
var instanceID = notification.InstanceID;
var createdDate = notification.CreatedDate;
var title = notification.Title;
var message = notification.Message;
var category = notification.Category;
var externalURL = notification.ExternalURL;
var read = notification.Read;
var target = notification.Target;
var hasReward = notification.HasReward;
var rewarded = notification.Rewarded;
var reward = notification.Reward;
var customData = notification.GetCustomData<CBSNotificationCustomData>();
}
}
}
}
CBSNotificationModule.MarkNotificationAsRead - Mark notification as read for profile
using CBS;
using CBS.Models;
using UnityEngine;
public class NotificationExample : MonoBehaviour
{
private INotificationCenter NotificationCenter { get; set; }
private void Start()
{
NotificationCenter = CBSModule.Get<CBSNotificationModule>();
var instanceID = "notification instance id";
NotificationCenter.MarkNotificationAsRead(instanceID, OnMark);
}
private void OnMark(CBSModifyNotificationResult result)
{
if (result.IsSuccess)
{
var updatedNotification = result.Notification;
}
}
}
CBSNotificationModule.RemoveNotification - Remove notification from profile list
using CBS;
using CBS.Models;
using UnityEngine;
public class NotificationExample : MonoBehaviour
{
private INotificationCenter NotificationCenter { get; set; }
private void Start()
{
NotificationCenter = CBSModule.Get<CBSNotificationModule>();
var instanceID = "notification instance id";
NotificationCenter.RemoveNotification(instanceID, OnRemove);
}
private void OnRemove(CBSModifyNotificationResult result)
{
if (result.IsSuccess)
{
var removedNotification = result.Notification;
}
}
}
CBSNotificationModule.ClaimNotificationReward - Claim notification reward.
using CBS;
using CBS.Models;
using UnityEngine;
public class NotificationExample : MonoBehaviour
{
private INotificationCenter NotificationCenter { get; set; }
private void Start()
{
NotificationCenter = CBSModule.Get<CBSNotificationModule>();
var instanceID = "notification instance id";
NotificationCenter.ClaimNotificationReward(instanceID, OnGet);
}
private void OnGet(CBSClaimNotificationRewardResult result)
{
if (result.IsSuccess)
{
var updatedNotification = result.Notification;
var rewardResult = result.RewardResult;
var grantedInstances = rewardResult.GrantedInstances;
var grantedCurrencies = rewardResult.GrantedCurrencies;
}
}
}
CBSNotificationModule.GetNotificationBadge - Get count of not read and not rewarded notifications
using CBS;
using CBS.Models;
using UnityEngine;
public class NotificationExample : MonoBehaviour
{
private INotificationCenter NotificationCenter { get; set; }
private void Start()
{
NotificationCenter = CBSModule.Get<CBSNotificationModule>();
NotificationCenter.GetNotificationBadge(OnGet);
}
private void OnGet(CBSBadgeResult result)
{
if (result.IsSuccess)
{
var badgeCount = result.Count;
}
}
}
CBSNotificationModule.SendNotificationToProfile - Send notification to profile
using System.Collections.Generic;
using CBS;
using CBS.Models;
using UnityEngine;
public class NotificationExample : MonoBehaviour
{
private INotificationCenter NotificationCenter { get; set; }
private void Start()
{
NotificationCenter = CBSModule.Get<CBSNotificationModule>();
var request = new CBSSendNotificationRequest
{
ToProfileID = "ProfileID to send",
NotificationTemplate = new ProfileNotificationTemplate
{
Title = "Invite",
Message = "Hello",
RewardObject = new RewardObject
{
BundledItems = new List<string>(){ "item id to send" }
},
CustomData = new NotificationData
{
TestString = "some data"
}
}
};
NotificationCenter.SendNotificationToProfile(request, OnSent);
}
private void OnSent(CBSSendNotificationResult result)
{
if (result.IsSuccess)
{
var notification = result.Notification;
}
}
}
Last updated