Hello,
im new to push notification service, i have implemented all which was given in the tutorial on how to push notification using playfab,
1)i imported playfab and android push sdk
2)registered on push notification in settings of playfab https://developer.playfab.com/en-us/TITLEID/settings/general
3) Wrote a script to push notification when application closes
4) received null reference error upon calling SendNotification function because of AndroidJavaClass that could only be run on device not on editor
5)tried everything cant receive the notification, please help
using PlayFab; using PlayFab.ClientModels; using UnityEngine; using PlayFab.Android; using PlayFab.Json; using System.Globalization; using System; using PlayFab.SharedModels; namespace PlayFab.Android { public class UniPushScript : MonoBehaviour { private string _lastMessageReceived = "waiting for message..."; // YOU MUST REPLACE THESE VALUES WITH YOUR TITLE AND YOUR SENDER // This is an existing PlayFab title, which is already set up, but you should not use it for more than a single test notification private const string TITLE_ID = "MYTITLEIDFROMPLAYFAB"; // TODO: Use your own titleId private const string ANDROID_PUSH_SENDER_ID = "MYSENDERIDFROMFIREBASECONSLOLE"; // TODO: Use your own FCM SenderId void Awake() { if (Instance) { Destroy (this.gameObject); } else { DontDestroyOnLoad (this); Instance = this; } } private void Start() { PlayFabSettings.TitleId = TITLE_ID; PlayFabAndroidPushPlugin.Setup(ANDROID_PUSH_SENDER_ID); PlayFabAndroidPushPlugin.AlwaysShowOnNotificationBar(true); PlayFabAndroidPushPlugin.OnGcmMessage += OnPushReceived; PlayFabAndroidPushPlugin.OnGcmLog += OnPushLog; // PlayFabAndroidPushPlugin.SendConfirmationMessage = true; // OPTIONAL: This sends a confirmation message when you register // PlayFabAndroidPushPlugin.ConfirmationMessage = "Push notifications registered successfully"; // OPTIONAL: This sends a confirmation message when you register StartLoginSequence(); } private static void OnSharedFailure(PlayFabError error) { Debug.LogError(error.GenerateErrorReport()); } void StartLoginSequence() { var loginRequest = new LoginWithCustomIDRequest { CustomId = SystemInfo.deviceUniqueIdentifier, CreateAccount = true, }; PlayFabClientAPI.LoginWithCustomID(loginRequest, OnLoginSuccess, OnSharedFailure); } void OnLoginSuccess(LoginResult result) { PlayFabAndroidPushPlugin.TriggerManualRegistration(); Debug.Log ("Login Sucess"); } void OnPushReceived(PlayFabNotificationPackage package) { _lastMessageReceived = JsonWrapper.SerializeObject(package); } void OnPushLog(string msg) { if (!msg.StartsWith("Token:")) return; Debug.Log(msg); msg = msg.Replace("Token:",""); _lastMessageReceived += "\n\n" + msg; } public void SchedulePushLocal() { var sDate = DateTime.Now; // UTC USAGE MUST be consistent #1 sDate = sDate.AddMinutes(2); var newNotification = new PlayFabNotificationPackage() { ScheduleDate = sDate, ScheduleType = ScheduleTypes.ScheduledLocal, // UTC USAGE MUST be consistent #2 Message = "This is Message", Title = "Waiting" }; PlayFabAndroidPushPlugin.SendNotification(newNotification); } void OnApplicationQuit() { SchedulePushLocal (); } } }