public void SendNotificationAndCoins(string friendUsername) { DatabaseReference reference = FirebaseDatabase.DefaultInstance.RootReference; reference.Child("usernameList").Child(friendUsername).GetValueAsync().ContinueWith(task => { DataSnapshot snapshot = task.Result; Dictionary <string, object> notification = new Dictionary <string, object>(); notification["headings"] = new Dictionary <string, string>() { { "en", "🚨🚨 We have a new member in your group 🚨🚨" } }; notification["contents"] = new Dictionary <string, string>() { { "en", "@" + username.ToLower() + " has joined your group! Come say hi 👋" } }; notification["include_player_ids"] = new List <string>() { snapshot.Value.ToString().Trim() }; OneSignal.PostNotification(notification); reference.Child("users").Child(friendUsername).Child("coins").GetValueAsync().ContinueWith(task2 => { DataSnapshot snapshot2 = task2.Result; int totalCoins = int.Parse(snapshot2.Value.ToString()) + 30; Dictionary <string, object> coinsData = new Dictionary <string, object>() { { "coins", totalCoins }, }; reference.Child("users").Child(friendUsername).UpdateChildrenAsync(coinsData); }); }); }
public static void someMethod(int day) { OneSignal.ClearOneSignalNotifications(); // Just an example userId, use your own or get it the devices by calling OneSignal.GetIdsAvailabl var notification = new Dictionary <string, object>(); if (Application.systemLanguage == SystemLanguage.Russian) { notification["contents"] = new Dictionary <string, string>() { { TextManager.getText("push_locale_text"), TextManager.getText("push_" + day.ToString() + "_text") }, { "en", "Cats prepared a gift! Come and get it!" } }; } else { notification["contents"] = new Dictionary <string, string>() { { TextManager.getText("push_locale_text"), TextManager.getText("push_" + day.ToString() + "_text") } }; } notification["include_player_ids"] = new List <string>() { Id }; //Test!!!! var additional_hours = 24 - System.DateTime.Now.Hour + 17; //var additional_hours = 24 - System.DateTime.Now.Hour + 8; // Example of scheduling a notification in the future. notification["send_after"] = System.DateTime.Now.ToUniversalTime().AddHours(additional_hours).ToString("U"); //notification["send_after"] = System.DateTime.Now.ToUniversalTime().AddMinutes(5).ToString("U"); OneSignal.PostNotification(notification, (responseSuccess) => { oneSignalDebugMessage = "Notification posted successful! Delayed by about 30 secounds to give you time to press the home button to see a notification vs an in-app alert.\n" + Json.Serialize(responseSuccess); Debug.Log(oneSignalDebugMessage); }, (responseFailure) => { oneSignalDebugMessage = "Notification failed to post:\n" + Json.Serialize(responseFailure); Debug.Log(oneSignalDebugMessage); }); }
public void PostNotification(string ID) { print("Post Notification Called"); if (SecurePlayerPrefs.GetInt("ActiveMessage", 0) == 0) { if (ID != null) { print(ID); var notification = new Dictionary <string, object>(); notification["contents"] = new Dictionary <string, string>() { { "en", "Your stars are ready to be collected" } }; notification["headings"] = new Dictionary <string, string>() { { "en", "Free Stars!🌟" } }; notification["include_player_ids"] = new List <string>() { ID }; // Example of scheduling a notification in the future. notification["send_after"] = System.DateTime.Now.ToUniversalTime().AddHours(12).ToString("U"); OneSignal.PostNotification(notification, (responseSuccess) => { print("Success"); oneSignalDebugMessage = "Notification posted successful! Delayed by about 30 secounds to give you time to press the home button to see a notification vs an in-app alert.\n" + Json.Serialize(responseSuccess); SecurePlayerPrefs.SetInt("ActiveMessage", 1); }, (responseFailure) => { print("Failure"); oneSignalDebugMessage = "Notification failed to post:\n" + Json.Serialize(responseFailure); }); } else { print("User ID not found"); OneSignal.SetSubscription(true); } } else { print("Message already being sent"); } }
public void SendNotification(string playerID, string headings, string contents) { Dictionary <string, object> notification = new Dictionary <string, object>(); notification["headings"] = new Dictionary <string, string>() { { "en", headings } }; notification["contents"] = new Dictionary <string, string>() { { "en", contents } }; notification["include_player_ids"] = new List <string>() { playerID }; OneSignal.PostNotification(notification); }
public void SendNotification(string externalPlayerID, string message) { Dictionary <string, object> notification = new Dictionary <string, object>(); notification["headings"] = new Dictionary <string, string>() { { "en", "@" + username.ToLower() + " " + message } }; notification["contents"] = new Dictionary <string, string>() { { "en", "Check out their world!" } }; notification["include_external_user_ids"] = new List <string>() { externalPlayerID }; OneSignal.PostNotification(notification); }
protected virtual void SendNotification(string message, int addedHours, int addedMinutes, int addedSeconds) { OneSignal.IdsAvailable((userId, token) => { if (token == null) { return; } extraMessage = "Waiting to get a OneSignal userId. Uncomment OneSignal. SetLogLevel in the 'Start' method if it hangs here to debug the issue."; var localTime = System.DateTime.Now.ToUniversalTime(); var notification = new Dictionary <string, object>(); notification["contents"] = new Dictionary <string, string>() { { "en", string.Format("{0} ({1}:{2}:{3})", message, localTime.Hour.ToString("00"), localTime.Minute.ToString("00"), localTime.Second.ToString("00")) } }; // Send notification to this device. notification["include_player_ids"] = new List <string>() { userId }; // Example of scheduling a notification in the future. notification["send_after"] = localTime.AddSeconds(addedSeconds).AddMinutes(addedMinutes).AddHours(addedHours).ToString("U"); extraMessage = "Posting test notification now."; OneSignal.PostNotification(notification, (responseSuccess) => { extraMessage = "Notification posted successful! Delayed by a predetermined time amount to give you time to press the home button to see a notification vs an in-app alert.\n" + Json.Serialize(responseSuccess); }, (responseFailure) => { extraMessage = "Notification failed to post:\n" + Json.Serialize(responseFailure); }); OneSignal.ClearOneSignalNotifications(); }); }
public void sendPushMessage(string message, string title = "Kubera") { OneSignal.GetIdsAvailable((userId, pushToken) => { if (pushToken != null) { // See http://documentation.onesignal.com/v2.0/docs/notifications-create-notification for a full list of options. // You can not use included_segments or any fields that require your OneSignal 'REST API Key' in your app for security reasons. // If you need to use your OneSignal 'REST API Key' you will need your own server where you can make this call. var notification = new Dictionary <string, object>(); notification["contents"] = new Dictionary <string, string>() { { "en", "Test Message" } }; notification["headings"] = new Dictionary <string, string>() { { "en", title } }; // Send notification to this device. notification["include_player_ids"] = new List <string>() { userId }; // Example of scheduling a notification in the future. notification["send_after"] = System.DateTime.Now.ToUniversalTime().AddSeconds(30).ToString("U"); //extraMessage = "Posting test notification now."; OneSignal.PostNotification(notification, (responseSuccess) => { //extraMessage = "Notification posted successful! Delayed by about 30 secounds to give you time to press the home button to see a notification vs an in-app alert.\n" + Json.Serialize(responseSuccess); }, (responseFailure) => { //extraMessage = "Notification failed to post:\n" + Json.Serialize(responseFailure); }); } else { Debug.LogWarning("ERROR: Device is not registered."); } }); }
public void SendNotification(string friendUsername) { DatabaseReference reference = FirebaseDatabase.DefaultInstance.RootReference; reference.Child("usernameList").Child(friendUsername).GetValueAsync().ContinueWith(task => { DataSnapshot snapshot = task.Result; Dictionary <string, object> notification = new Dictionary <string, object>(); notification["headings"] = new Dictionary <string, string>() { { "en", "Someone is in your world 🌎" } }; notification["contents"] = new Dictionary <string, string>() { { "en", "@" + myUsername.ToLower() + " is visiting you! Come say hi 👋" } }; notification["include_player_ids"] = new List <string>() { snapshot.Value.ToString().Trim() }; OneSignal.PostNotification(notification); }); }
// Test Notification private void SendNotification() { var extraMessage = ""; OneSignal.IdsAvailable((userId, pushToken) => { userId = OneSignal.GetPermissionSubscriptionState().subscriptionStatus.userId; if (pushToken != null) { // See http://documentation.onesignal.com/docs/notifications-create-notification for a full list of options. // You can not use included_segments or any fields that require your OneSignal 'REST API Key' in your app for security reasons. // If you need to use your OneSignal 'REST API Key' you will need your own server where you can make this call. var notification = new Dictionary <string, object>(); notification["contents"] = new Dictionary <string, string>() { { "en", "Made with Unity" } }; // Send notification to this device. notification["include_player_ids"] = new List <string>() { userId }; // Example of scheduling a notification in the future. notification["send_after"] = DateTime.Now.ToUniversalTime().AddSeconds(0).ToString("U"); extraMessage = "Posting test notification now."; OneSignal.PostNotification(notification, (responseSuccess) => { extraMessage = "Notification posted successful! Delayed by about 30 secounds to give you time to press the home button to see a notification vs an in-app alert.\n" + Json.Serialize(responseSuccess); }, (responseFailure) => { extraMessage = "Notification failed to post:\n" + Json.Serialize(responseFailure); }); } else { extraMessage = "ERROR: Device is not registered."; } }); }
// Test Menu // Includes SendTag/SendTags, getting the userID and pushToken, and scheduling an example notification void OnGUI() { GUIStyle customTextSize = new GUIStyle("button"); customTextSize.fontSize = 30; GUIStyle guiBoxStyle = new GUIStyle("box"); guiBoxStyle.fontSize = 30; GUIStyle textFieldStyle = new GUIStyle("textField"); textFieldStyle.fontSize = 30; float itemOriginX = 50.0f; float itemWidth = Screen.width - 120.0f; float boxWidth = Screen.width - 20.0f; float boxOriginY = 120.0f; float boxHeight = requiresUserPrivacyConsent ? 980.0f : 890.0f; float itemStartY = 200.0f; float itemHeightOffset = 90.0f; float itemHeight = 60.0f; GUI.Box(new Rect(10, boxOriginY, boxWidth, boxHeight), "Test Menu", guiBoxStyle); float count = 0.0f; if (GUI.Button(new Rect(itemOriginX, itemStartY + (count * itemHeightOffset), itemWidth, itemHeight), "SendTags", customTextSize)) { // You can tags users with key value pairs like this: OneSignal.SendTag("UnityTestKey", "TestValue"); // Or use an IDictionary if you need to set more than one tag. OneSignal.SendTags(new Dictionary <string, string>() { { "UnityTestKey2", "value2" }, { "UnityTestKey3", "value3" } }); // You can delete a single tag with it's key. // OneSignal.DeleteTag("UnityTestKey"); // Or delete many with an IList. // OneSignal.DeleteTags(new List<string>() {"UnityTestKey2", "UnityTestKey3" }); } count++; if (GUI.Button(new Rect(itemOriginX, itemStartY + (count * itemHeightOffset), itemWidth, itemHeight), "GetIds", customTextSize)) { OneSignal.IdsAvailable((userId, pushToken) => { extraMessage = "UserID:\n" + userId + "\n\nPushToken:\n" + pushToken; }); } count++; if (GUI.Button(new Rect(itemOriginX, itemStartY + (count * itemHeightOffset), itemWidth, itemHeight), "TestNotification", customTextSize)) { extraMessage = "Waiting to get a OneSignal userId. Uncomment OneSignal.SetLogLevel in the Start method if it hangs here to debug the issue."; OneSignal.IdsAvailable((userId, pushToken) => { if (pushToken != null) { // See http://documentation.onesignal.com/docs/notifications-create-notification for a full list of options. // You can not use included_segments or any fields that require your OneSignal 'REST API Key' in your app for security reasons. // If you need to use your OneSignal 'REST API Key' you will need your own server where you can make this call. var notification = new Dictionary <string, object>(); notification["contents"] = new Dictionary <string, string>() { { "en", "Test Message" } }; // Send notification to this device. notification["include_player_ids"] = new List <string>() { userId }; // Example of scheduling a notification in the future. notification["send_after"] = System.DateTime.Now.ToUniversalTime().AddSeconds(30).ToString("U"); extraMessage = "Posting test notification now."; OneSignal.PostNotification(notification, (responseSuccess) => { extraMessage = "Notification posted successful! Delayed by about 30 secounds to give you time to press the home button to see a notification vs an in-app alert.\n" + Json.Serialize(responseSuccess); }, (responseFailure) => { extraMessage = "Notification failed to post:\n" + Json.Serialize(responseFailure); }); } else { extraMessage = "ERROR: Device is not registered."; } }); } count++; email = GUI.TextField(new Rect(itemOriginX, itemStartY + (count * itemHeightOffset), itemWidth, itemHeight), email, customTextSize); count++; if (GUI.Button(new Rect(itemOriginX, itemStartY + (count * itemHeightOffset), itemWidth, itemHeight), "SetEmail", customTextSize)) { extraMessage = "Setting email to " + email; OneSignal.SetEmail(email, () => { Debug.Log("Successfully set email"); }, (error) => { Debug.Log("Encountered error setting email: " + Json.Serialize(error)); }); } count++; if (GUI.Button(new Rect(itemOriginX, itemStartY + (count * itemHeightOffset), itemWidth, itemHeight), "LogoutEmail", customTextSize)) { extraMessage = "Logging Out of [email protected]"; OneSignal.LogoutEmail(() => { Debug.Log("Successfully logged out of email"); }, (error) => { Debug.Log("Encountered error logging out of email: " + Json.Serialize(error)); }); } count++; externalId = GUI.TextField(new Rect(itemOriginX, itemStartY + (count * itemHeightOffset), itemWidth, itemHeight), externalId, customTextSize); count++; if (GUI.Button(new Rect(itemOriginX, itemStartY + (count * itemHeightOffset), itemWidth, itemHeight), "SetExternalId", customTextSize)) { extraMessage = "Setting External User Id"; OneSignal.SetExternalUserId(externalId); } count++; if (GUI.Button(new Rect(itemOriginX, itemStartY + (count * itemHeightOffset), itemWidth, itemHeight), "RemoveExternalId", customTextSize)) { extraMessage = "Removing External User Id"; OneSignal.RemoveExternalUserId(); } if (requiresUserPrivacyConsent) { count++; if (GUI.Button(new Rect(itemOriginX, itemStartY + (count * itemHeightOffset), itemWidth, itemHeight), (OneSignal.UserProvidedConsent() ? "Revoke Privacy Consent" : "Provide Privacy Consent"), customTextSize)) { extraMessage = "Providing user privacy consent"; OneSignal.UserDidProvideConsent(!OneSignal.UserProvidedConsent()); } } if (extraMessage != null) { guiBoxStyle.alignment = TextAnchor.UpperLeft; guiBoxStyle.wordWrap = true; GUI.Box(new Rect(10, boxOriginY + boxHeight + 20, Screen.width - 20, Screen.height - (boxOriginY + boxHeight + 40)), extraMessage, guiBoxStyle); } }
// Test Menu // Includes SendTag/SendTags, getting the userID and pushToken, and scheduling an example notification void OnGUI() { GUIStyle customTextSize = new GUIStyle("button"); customTextSize.fontSize = 30; GUIStyle guiBoxStyle = new GUIStyle("box"); guiBoxStyle.fontSize = 30; GUI.Box(new Rect(10, 10, 390, 340), "Test Menu", guiBoxStyle); if (GUI.Button(new Rect(60, 80, 300, 60), "SendTags", customTextSize)) { // You can tags users with key value pairs like this: OneSignal.SendTag("UnityTestKey", "TestValue"); // Or use an IDictionary if you need to set more than one tag. OneSignal.SendTags(new Dictionary <string, string>() { { "UnityTestKey2", "value2" }, { "UnityTestKey3", "value3" } }); // You can delete a single tag with it's key. // OneSignal.DeleteTag("UnityTestKey"); // Or delete many with an IList. // OneSignal.DeleteTags(new List<string>() {"UnityTestKey2", "UnityTestKey3" }); } if (GUI.Button(new Rect(60, 170, 300, 60), "GetIds", customTextSize)) { OneSignal.GetIdsAvailable((userId, pushToken) => { extraMessage = "UserID:\n" + userId + "\n\nPushToken:\n" + pushToken; }); } if (GUI.Button(new Rect(60, 260, 300, 60), "TestNotification", customTextSize)) { extraMessage = "Waiting to get a OneSignal userId. Uncomment OneSignal.SetLogLevel in the Start method if it hangs here to debug the issue."; OneSignal.GetIdsAvailable((userId, pushToken) => { if (pushToken != null) { // See http://documentation.onesignal.com/v2.0/docs/notifications-create-notification for a full list of options. // You can not use included_segments or any fields that require your OneSignal 'REST API Key' in your app for security reasons. // If you need to use your OneSignal 'REST API Key' you will need your own server where you can make this call. var notification = new Dictionary <string, object>(); notification["contents"] = new Dictionary <string, string>() { { "en", "Test Message" } }; // Send notification to this device. notification["include_player_ids"] = new List <string>() { userId }; // Example of scheduling a notification in the future. notification["send_after"] = System.DateTime.Now.ToUniversalTime().AddSeconds(30).ToString("U"); extraMessage = "Posting test notification now."; OneSignal.PostNotification(notification, (responseSuccess) => { extraMessage = "Notification posted successful! Delayed by about 30 secounds to give you time to press the home button to see a notification vs an in-app alert.\n" + Json.Serialize(responseSuccess); }, (responseFailure) => { extraMessage = "Notification failed to post:\n" + Json.Serialize(responseFailure); }); } else { extraMessage = "ERROR: Device is not registered."; } }); } if (extraMessage != null) { guiBoxStyle.alignment = TextAnchor.UpperLeft; guiBoxStyle.wordWrap = true; GUI.Box(new Rect(10, 390, Screen.width - 20, Screen.height - 400), extraMessage, guiBoxStyle); } }