토큰 저장
푸시 발송을 위한 토큰을 저장합니다
호출 정보
PushNotification.Save(string token, PlayNANOODelegate callback) {}
PushNotification.Save(string token, bool receiveYn, bool receiveNightYn, PlayNANOODelegate callback) {}
호출 상세 정보
파라미터 | 설명 | 타입 |
---|---|---|
token | 푸시 토큰 | string |
receiveYn | 푸시 메시지 수신 여부 | boolean |
receiveNightYn | 야간 푸시 (오후 09시 ~ 다음날 오전 08시) 메시지 수신 여부 | boolean |
callback | 통신 결과 | PlayNANOODelegate |
안드로이드 요청
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 요청 (Unity 2020.x 이상 버전)
- Unity Package Manager 에서 Mobile Notifications을 설치합니다.
- Project Settings > Mobile Notifications > iOS 에서 Enable Push Notifications, 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 요청 (Unity 2019.x 이하버전)
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");
}
});
}
}
통신 결과
HTTP/1.1 200 OK
Content-Type: application/json;charset=UTF-8
{
"Status" : "String"
}
통신 결과 상세 정보
데이터키 | 설명 | 타입 |
---|---|---|
Status | 처리 결과 | string |