DeviceType In Unity Documentation For Push Notifications Regarding Storage of Device Token

0 votes
 

<<<<<<<<<<<<<<<<<<<<<<UPDATE>>>>>>>>>>>>>>>>>>>>>>>

With the code in the comments (8000 character limit won't let me post), after Google Play updated the APK, I now have a little bit of success.  A user was created in the Push Notifications channel with a device ID much like yours in the tutorial, "APA91bHGWMa4F5WbImBbXy7bY3AYhNDOo2H2wRdKT3p_WMBAJXFF8CQYH8EJF_LevGcppVL6un-LFwiJiPYSYWifjK243DMT62biN6-Rr6uyS6p-DNEz5DO1txPLSc5CNVkmbNHouUKs".

When I send a push notification through APPHQ, I still don't receive a notification on the device.  Also, the project in Google Developer's Console shows zero hits:

asked Nov 27, 2015 in App42 Cloud API-BaaS by null (23 points)
edited Nov 29, 2015 by null
using System;
using UnityEngine;
using UnityEngine.UI;
//User management directives.
using com.shephertz.app42.paas.sdk.csharp;
using com.shephertz.app42.paas.sdk.csharp.user;
//Push notification directives.
using com.shephertz.app42.paas.sdk.csharp.pushNotification;
using AssemblyCSharpfirstpass;

public class App42PushTest : MonoBehaviour, App42NativePushListener {
    //Input fields.
    public InputField APIKey;
    public InputField APIKeySecret;
    public InputField CreateUser;
    public InputField ProjectID;
    public InputField RegisterUser;
    public InputField PushNotification;
    public InputField Console;
    //Services.
    public static ServiceAPI serviceAPI;
    public static UserService userService;
    public static PushNotificationService pushNotificationService;
    public static PushNotification pushNotification;
    // Use this for initialization
    void Start () {

        DontDestroyOnLoad(transform.gameObject);
    }
   
    // Update is called once per frame
    void Update () {
   
    }

    public void CreateNewUser ()
    {
        //Send console message.
        SendConsoleMessage("Initializing App42 service...");
        //Instantiate the services.
        serviceAPI = new ServiceAPI(APIKey.text, APIKeySecret.text);
        SendConsoleMessage("Service initialized.");
        //User services.
        SendConsoleMessage("Building user service...");
        userService = serviceAPI.BuildUserService();
        SendConsoleMessage("User service build complete.");
        //Create the new user.
        SendConsoleMessage("Creating user...");
        SendConsoleMessage("Username: " + CreateUser.text);
        SendConsoleMessage("Password: " + CreateUser.text);
        SendConsoleMessage("Email: " + CreateUser.text + "@" + CreateUser.text + ".com");
        userService.CreateUser(CreateUser.text, CreateUser.text, CreateUser.text + "@" + CreateUser.text + ".com", new NewUserCallBack());
    }

    public void RegisterNewUser ()
    {
        //Build the push service.
        SendConsoleMessage("Building push service...");
        pushNotificationService = App42API.BuildPushNotificationService();
        SendConsoleMessage("Push service build complete.");
        //Store the device token.
        //SendConsoleMessage("Creating device token...");
        //string deviceToken = SystemInfo.deviceUniqueIdentifier;
        //SendConsoleMessage("Device token: " + deviceToken);
        SendConsoleMessage("Creating device type...");
        string deviceType = com.shephertz.app42.paas.sdk.csharp.pushNotification.DeviceType.ANDROID;
        SendConsoleMessage("Device type: " + deviceType);
        SendConsoleMessage("Adding listener class...");
        App42Push.setApp42PushListener(this);
        SendConsoleMessage("Listener class added.");
        //SendConsoleMessage("Registering user token...");
        //pushNotificationService.StoreDeviceToken(RegisterUser.text, deviceToken, deviceType, new RegisterUserCallBack());
        App42Push.registerForPush(ProjectID.text);
    }

    public void SendConsoleMessage (string TheMessage)
    {
        Console.text += TheMessage;
        Console.text += "\n";
        Console.MoveTextEnd(true);
    }

    // Register for Push Notification when you get regsitartion Id  
    public void onDeviceToken(String deviceToken)
    {
        Debug.Log("Device token from native: " + deviceToken);
        String deviceType = App42Push.getDeviceType();
        if (deviceType != null && deviceToken != null && deviceToken.Length != 0)
            App42API.BuildPushNotificationService().StoreDeviceToken(App42API.GetLoggedInUser(), deviceToken, deviceType, new Callback());

        Debug.Log("device token called");
    }

    //Push message from native  
    public void onMessage(String msg)
    {
        Debug.Log("Message From native: " + msg);
    }

    //Error message from native  
    public void onError(String error)
    {
        Debug.Log("Error From native: " + error);
    }

    public class NewUserCallBack : App42CallBack
    {
        //Singleton.  This can be ignored.  This is just to access external class.
        App42PushTest A42PT = Singleton<App42PushTest>.Instance.GetComponent<App42PushTest>();
        public void OnSuccess(object response)
        {
            User user = (User)response;

            A42PT.SendConsoleMessage("User creation successful.");
            A42PT.SendConsoleMessage("Username: " + user.GetUserName());
            A42PT.SendConsoleMessage("Password: " + user.GetPassword());
            A42PT.SendConsoleMessage("Email: " + user.GetEmail());

            A42PT.SendConsoleMessage("Setting session ID...");
            App42PushTest.userService.SetSessionId(user.GetSessionId());
            A42PT.SendConsoleMessage("Session ID set.");

            A42PT.SendConsoleMessage("Logging in user...");
            App42API.SetLoggedInUser(A42PT.RegisterUser.text);
            A42PT.SendConsoleMessage("User logged in.");
        }

        public void OnException(Exception e)
        {
            A42PT.SendConsoleMessage("USER CREATION FAILED");
        }
    }
}

1 Answer

+1 vote

Hello Developer,

Yes, you are right the third parameter in store device token method take value as a string. But in order to get the exact value of platform from client, we have created one enum class and according to device type developers can choose their platform. For example: In documentation  DeviceType.ANDROID is used for Android device.  

I believe it will answer your concern, if you need further help regarding this. Please let us know, we are happy to help you. 

Regards,

Himanshu Sharma

 

answered Nov 28, 2015 by hs00105 (2,005 points)
I'm still not able to obtain a device ID or device type because of errors.  I'm going to make a small game and show you step-by-step, what I'm doing.  I'll be a few hours.
I updated the question.  Thanks.
Hello Developer,

Could you please check your push logs and share that logs with us? It will help us to find the root cause of this issue. In order to see the push logs, please click on Unified Notification -> Push -> Logs.

P.S Please enable your push logs from App Manager settings page, if you have not enabled it yet.

Regards,
Himanshu Sharma
I enabled them now.  It turns out the problem was with the manifest file which is now fixed.  Also, I didn't need to call StoreDeviceToken

Thank you for all of your help. :)
Great to hear that your query has been resolved. let us know if you need any other help from our side, while integrating it.

We are Happy to address your concern.

Regards,
Himanshu Sharma
Download Widgets
Welcome to ShepHertz Product line forum, where you can ask questions and receive answers from the community. You can also reach out to us on support@shephertz.com
...