- Home /
Device Token requirement in push notification
I actually implemented push notification service into my game but I have some questions in my mind those I want to clear.
Implementation totally done on our custom server so not used any third party service help in this. I have used core Unity push notification code for this purpose.
NotificationServices.deviceToken
After registration was complete, I need to add deviceToken to web server. Why I need to do this? I can't able to get this concept.
If I add SystemInfo.deviceUniqueIdentifier then it will not able to send any push notification. It can only able to work with deviceToken.
Please share your suggestions with this.
I have the same problem.
NotificationServices.deviceToken is for iOS only but it always returns null for me. (Great instructions about how to setup push notifications with certificates here: https://github.com/argon/node-apn/wiki/Preparing-Certificates)
For Andorid; I can't see any way to get push notification device token.
Answer by DVFrance · Dec 21, 2016 at 03:28 PM
Hello I'm working on it and it's drive me crazy. I also need device token for android and I can't find a way to know it, I tried with SystemInfo.deviceUniqueIdentifier on this http://www.pushwatch.com/gcm/. And It doesn't work.
Any idea will be helpfull ! Tks
Answer by Bimaokai · Oct 12, 2020 at 01:04 PM
,Hi, I know this is very old but maybe it helps somebody.
In the Start Method I am calling this one:
 UnityEngine.iOS.NotificationServices.RegisterForNotifications(
                 UnityEngine.iOS.NotificationType.Alert |
                 UnityEngine.iOS.NotificationType.Badge |
                 UnityEngine.iOS.NotificationType.Sound);
 
Then in update I register the device ID to my own web service:
 public void RegisterClient()
     {
         if (!tokenSent && !workingOnRegistering)
         {
             workingOnRegistering = true;
             string theToken = "ABCDEFG......";
             byte[] token = UnityEngine.iOS.NotificationServices.deviceToken;
             if (token != null)
             {
                 theToken = System.BitConverter.ToString(token).Replace("-", "");
                 tokenSent = true;
             }
                 
 
             string url = String.Format("myURL");
             UnityWebRequest webRequest = new UnityWebRequest(url, "POST");            
             byte[] encodedPayload = new System.Text.UTF8Encoding().GetBytes("{\"deviceID\":\""+theToken+"\"}");
 
             webRequest.uploadHandler = (UploadHandler)new UploadHandlerRaw(encodedPayload);
             webRequest.downloadHandler = (DownloadHandler)new DownloadHandlerBuffer();
             webRequest.SetRequestHeader("Content-Type", "application/json");
             webRequest.SetRequestHeader("cache-control", "no-cache");
 
             UnityWebRequestAsyncOperation requestHandel = webRequest.SendWebRequest();
             requestHandel.completed += delegate (AsyncOperation pOperation) {
                 /*Debug.Log(webRequest.responseCode);
                 Debug.Log(webRequest.downloadHandler.text);*/
             };
             workingOnRegistering = false;
         }
     }
 
Your answer
 
 
             Follow this Question
Related Questions
Unity and ARkit Plugin - Please Help 0 Answers
image got pixelated on ios device 0 Answers
How to load tdb file in unity? 1 Answer
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                