Save Token
Saves a token for sending push notifications.
Call Information
PushNotification.Save(string token, PlayNANOODelegate callback) {}
PushNotification.Save(string token, bool receiveYn, bool receiveNightYn, PlayNANOODelegate callback) {}
Call Details
| Parameter | Description | Type |
|---|---|---|
| token | Push token | string |
| receiveYn | Whether to receive push messages | boolean |
| receiveNightYn | Whether to receive nighttime push messages (9:00 PM ~ 8:00 AM next day) | boolean |
| callback | Communication result | PlayNANOODelegate |
Android Request
using PlayNANOO;
using Firebase;
public class PlayNANOOExample : MonoBehaviour
{
Plugin plugin;
void Start() {
plugin = Plugin.GetInstance();
Firebase.Messaging.FirebaseMessaging.TokenReceived += OnTokenReceived;
Firebase.Messaging.FirebaseMessaging.MessageReceived += OnMessageReceived;
}
public void OnTokenReceived(object sender, Firebase.Messaging.TokenReceivedEventArgs token) {
UnityEngine.Debug.Log("Received Registration Token: " + token.Token);
SaveToken(token.Token);
}
public void OnMessageReceived(object sender, Firebase.Messaging.MessageReceivedEventArgs e) {
UnityEngine.Debug.Log("Received a new message from: " + e.Message.From);
}
void SaveToken(string token)
{
string token = "string";
bool receiveYn = true;
bool receiveNightYn = true;
plugin.PushNotification.Save(token, receiveYn, receiveNightYn, (status, error, jsonString, values) =>
{
if (status.Equals(Configure.PN_API_STATE_SUCCESS))
{
Debug.Log("Success");
}
else
{
Debug.Log("Fail");
}
});
}
}
iOS Request (Unity 2020.x and above)

- Install Mobile Notifications from Unity Package Manager.

- In Project Settings > Mobile Notifications > iOS, check Enable Push Notifications and Register for Push Notifications on App Launch.
using PlayNANOO;
using Unity.Notifications.iOS;
public class PlayNANOOExample : MonoBehaviour
{
Plugin plugin;
void Start()
{
plugin = Plugin.GetInstance();
StartCoroutine(RequestAuthorization());
}
IEnumerator RequestAuthorization()
{
var authorizationOption = AuthorizationOption.Alert | AuthorizationOption.Badge;
using (var req = new AuthorizationRequest(authorizationOption, true))
{
while (!req.IsFinished)
{
yield return null;
};
plugin.PushNotification.Save(req.DeviceToken, (status, error, jsonString, values) => {
Debug.Log(jsonString);
});
}
}
}
iOS Request (Unity 2019.x and below)
using PlayNANOO;
using NotificationServices = UnityEngine.iOS.NotificationServices;
using NotificationType = UnityEngine.iOS.NotificationType;
public class PlayNANOOExample : MonoBehaviour
{
Plugin plugin;
void Start()
{
NotificationServices.RegisterForNotifications(NotificationType.Alert | NotificationType.Badge | NotificationType.Sound, true);
plugin = Plugin.GetInstance();
IOSToken();
}
void IOSToken()
{
byte[] token = NotificationServices.deviceToken;
if (token != null) SaveToken(System.BitConverter.ToString(token).Replace("-", ""));
}
void SaveToken(string token)
{
string token = "string";
bool receiveYn = true;
bool receiveNightYn = true;
plugin.PushNotification.Save(token, receiveYn, receiveNightYn, (status, error, jsonString, values) =>
{
if (status.Equals(Configure.PN_API_STATE_SUCCESS))
{
Debug.Log("Success");
}
else
{
Debug.Log("Fail");
}
});
}
}
Response
HTTP/1.1 200 OK
Content-Type: application/json;charset=UTF-8
{
"Status" : "String"
}
Response Details
| Data Key | Description | Type |
|---|---|---|
| Status | Processing result | string |