public void Send_Notifications_To_Not_Answered() { if (not_voted != null) { foreach (User.User_Information user in not_voted) { Send(user); } void Send(User.User_Information user) { Firebase_Handler.Send_Notification(new Firebase_Handler.FCM_Params() { User_Id = user.Id, Title = "", Body = "¡Hola " + user.Name + "! \n" + "Aún no hemos registrado ningun voto tuyo a la encuesta o el evento '" + votable.Title + "'. " + "Éste es un recordatorio cordial por parte de tod@s de que votes en cuanto puedas. ¡Un saludo!", Data_Pairs = new Dictionary <string, string>() { { "Load_type", Database_Handler.Selected_Data.GetType().ToString() }, { "Load_id", votable.Id.ToString() } } }); } } }
IEnumerator Initialize_() { App = FirebaseApp.DefaultInstance; FirebaseApp.LogLevel = LogLevel.Info; proj_id = App.Options.MessageSenderId; default_header = new Dictionary <string, string>() { { "Content-Type", "application/json" }, { "Authorization", "key=" + server_key }, { "project_id", proj_id } }; while (!User.Initialized) { yield return(null); } /*Firebase_Handler.Singleton.GoogleAnalytics.LogScreen("Login_S"); * Firebase_Handler.Singleton.GoogleAnalytics.LogEvent("Category_Example", "Event_Action", "Event_Label", 1); * Firebase_Handler.Singleton.GoogleAnalytics.LogEvent(new EventHitBuilder().SetEventCategory("login").SetEventAction("login")); * Firebase_Handler.Singleton.GoogleAnalytics.DispatchHits();*/ Set_User_Property("user_id", User.User_Info.Id.ToString()); #if !UNITY_EDITOR Firebase_Handler.Modify_Registration_Token(Firebase_Handler.Operation.add); #endif Debug.Log("Firebase initialized successfully. Data:" + "\nProjectId: " + App.Options.ProjectId + "\nMessageSenderId: " + App.Options.MessageSenderId + "\nAppId: " + App.Options.AppId + "\nApiKey: " + App.Options.ApiKey); yield return(null); }
public void Logout() { Database_Handler.Initialize_Dictionaries(); string lock_pwd = PlayerPrefs.GetString("lock_pwd"); string db_key = PlayerPrefs.GetString("db_key"); PlayerPrefs.DeleteAll(); PlayerPrefs.SetString("lock_pwd", lock_pwd); PlayerPrefs.SetString("db_key", db_key); Firebase_Handler.Modify_Registration_Token(Firebase_Handler.Operation.remove, new Firebase_Handler.FCM_Params() { Concluding_Method = (object[] data) => { User.Initialized = false; Firebase_Handler.Singleton.enabled = true; Firebase_Handler.Own_Notification_Key = ""; Scroll_Updater.Initialize(); for (int x = 0; x < SceneManager.sceneCount; x++) { Scene scene = SceneManager.GetSceneAt(x); if (scene.name != "Login") { SceneManager.UnloadSceneAsync(scene); } } User.User_Info = new User.User_Information { Username = "" }; } }); Login.Singleton.Reset_Input_Fields(); }
public void Confirm_Send_Notification() { if (User.User_Info.Role >= User.User_Role.moderator) { Dictionary <string, string> data_pairs = new Dictionary <string, string>(); switch (message_type) { case Message_Type.Copy_Notification: data_pairs.Add("Msg_Title", title.text); data_pairs.Add("Msg_Content", body.text); break; case Message_Type.Custom: data_pairs.Add("Msg_Title", title_message.text); data_pairs.Add("Msg_Content", body_message.text); break; } if (redirect_type != Redirect_Type.No_Redirect) { data_pairs.Add("Red_Type", redirect_type.ToString()); data_pairs.Add("Red_Id", redirect_id.text); } List <string> success = new List <string>(); List <string> no_device = new List <string>(); List <string> unknown = new List <string>(); foreach (User.User_Information info in searcher.Targets) { Firebase_Handler.Send_Notification(new Firebase_Handler.FCM_Params() { User_Id = info.Id, Title = title.text, Body = body.text, Data_Pairs = data_pairs, Concluding_Method = (object[] data) => { if ((string)data[2] == "0") { success.Add(info.Username); } else if ((string)data[2] == "-1" && (string)data[1] == "notification_key not found") { no_device.Add(info.Username); } else { unknown.Add(info.Username); } if (success.Count + no_device.Count + unknown.Count >= searcher.Targets.Count) { string message = ""; if (success.Count > 0) { message += "Éxito: " + Utils.List_To_String(success, ", ") + ". "; } if (no_device.Count > 0) { message += "Sin registrar: " + Utils.List_To_String(no_device, ", ") + ". "; } if (unknown.Count > 0) { message += "Error: " + Utils.List_To_String(unknown, ", ") + "."; } Debug.Log(message); Message.ShowMessage(message); } } }); } title.text = ""; body.text = ""; title_message.text = ""; body_message.text = ""; redirect_id.text = ""; } else { Message.ShowMessage(not_permitted_message); } }
// ______________________________________ // // 1. MONOBEHAVIOUR LIFECYCLE AND INITIALIZATION. // ______________________________________ // void Awake() { Singleton = this; }