Save Token
Saves token required for sending push notifications.
Call Information
PushNotification.Save(string token, PlayNANOODelegate callback) {}
PushNotification.Save(string token, bool receiveYn, bool receiveNightYn, PlayNANOODelegate callback) {}
Call Information Details
Parameter | Description | Type |
---|---|---|
token | Push notification token | string |
receiveYn | Push notification message receive status | boolean |
receiveNightYn | Night time push notification message receive status (9 PM to 9 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();
StartCoroutine(AndroidToken());
}
IEnumerator AndroidToken()
{
var task = Firebase.Messaging.FirebaseMessaging.GetTokenAsync();
while (!task.IsCompleted) yield return new WaitForEndOfFrame();
SaveToken(task.Result);
}
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)
!Figure 1. Install Mobile Notifications](https://playnanoo-public.s3-ap-northeast-1.amazonaws.com/I7wkArjVvJkLMIZplKTaBdRQnBL4gfxY1ZVktX9P.png)
- Install Mobile Notifications from Unity Package Manager.
!Figure 2. Mobile Notifications Setup](https://playnanoo-public.s3-ap-northeast-1.amazonaws.com/oYu94eerAN5nhM0An4uBIW2IX8LLnHTrGfHk4J43.png)
- In Project Settings > Mobile Notifications > iOS, 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");
}
});
}
}
Communication Result
HTTP/1.1 200 OK
Content-Type: application/json;charset=UTF-8
{
"Status" : "String"
}
Communication Result Details
Data Key | Description | Type |
---|---|---|
Status | Operation result | string |