1:Apple Developer Program から プッシュ通知サービスのチェックを付けて、AppIDsを作成
2:1で作成したAppIDsを使ってプロビジョニングプロファイルを作成
3:Unityを開き、1で作成したバンドルIDをセットする。
4:下記コードを実装してボタンから呼べるようにする。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GetToken : MonoBehaviour {
// Use this for initialization
void Start () {
UnityEngine.iOS.NotificationServices.RegisterForNotifications(
UnityEngine.iOS.NotificationType.Alert |
UnityEngine.iOS.NotificationType.Badge |
UnityEngine.iOS.NotificationType.Sound);
}
public void GetTokenString()
{
GetTokenData ();
}
private void GetTokenData ()
{
#if UNITY_IPHONE
string deviceToken = "";
// デバイストークン取得
byte[] token = UnityEngine.iOS.NotificationServices.deviceToken;
if (token != null)
{
deviceToken = System.BitConverter.ToString(token).Replace("-", "");
}
else
{
deviceToken = "Nothing";
}
// ベンダーID取得
string identifierForVendor = UnityEngine.iOS.Device.vendorIdentifier;
Debug.Log("deviceToken=" + deviceToken);
Debug.Log("identifierForVendor=" + identifierForVendor);
#endif
}
}
5:ビルドする。
6:Xcodeを開いて、Capabilitiesタブを選択して Push Notifications を ON にする。
7:Generalタブを選択して、SingingのAutomatically manage sigining のチェックを外す
8:Signing(Release)等のプロビジョニングプロファイルの設定を2で作成したものに設定する。
9:実行する。
10:実機にて通知を許可するか聞かれるので、「はい」を選択
11:ボタンをタップして、Xcodeのログにデバイストークンが表示される事を確認