/// <summary> /// Shows the rating request dialog with the default behavior and the given content. /// Use this method if you want to localize the dialog on Android or iOS older than 10.3 /// (on iOS 10.3 or newer, the rating dialog content is controlled by the system). /// </summary> /// <param name="dialogContent">Dialog content.</param> public static void RequestRating(RatingDialogContent dialogContent) { DoRequestRating(dialogContent, null); }
/// <summary> /// On Android or iOS older than 10.3, this method shows the rating request dialog /// with the given content and the callback will be invoked when the popup closes. /// You can use this method if you want to implement a custom behavior /// for the rating dialog. If you also want to localize it, pass a <see cref="RatingDialogContent"/> /// object holding the localized content, otherwise pass null to use the default content. /// On iOS 10.3 or newer, the system rating prompt is used, therefore the callback won't be invoked, /// and the dialog content is controlled by the system. /// </summary> /// <param name="dialogContent">Dialog content, pass null to use the default content.</param> /// <param name="callback">Callback receiving user selection as input. You need to /// implement this callback to take appropriate actions corresponding to the user input.</param> public static void RequestRating(RatingDialogContent dialogContent, Action <UserAction> callback) { DoRequestRating(dialogContent, callback); }
private static void DoRequestRating(RatingDialogContent content, Action <UserAction> callback) { if (!CanRequestRating()) { Debug.Log("Could not display the rating request popup because it was disabled, " + "or one or more display constraints are not satisfied."); return; } // If no custom content was provided, use the default one. if (content == null) { content = EM_Settings.RatingRequest.DefaultRatingDialogContent; } // Callback register customBehaviour = callback; #if UNITY_EDITOR Debug.Log("Request review is only available on iOS and Android devices."); #elif UNITY_IOS if (iOSNativeUtility.CanUseBuiltinRequestReview()) { // iOS 10.3+. iOSNativeUtility.RequestReview(); } else { // iOS before 10.3. MobileNativeAlert alert = MobileNativeAlert.ShowThreeButtonAlert( content.Title.Replace(RatingDialogContent.PRODUCT_NAME_PLACEHOLDER, Application.productName), content.Message.Replace(RatingDialogContent.PRODUCT_NAME_PLACEHOLDER, Application.productName), content.RefuseButtonText, content.PostponeButtonText, content.RateButtonText ); if (alert != null) { alert.OnComplete += OnIosRatingDialogCallback; } } if (!IsDisplayConstraintIgnored()) { // Increment the number of requests used this year. SetAnnualUsedRequests(DateTime.Now.Year, GetAnnualUsedRequests(DateTime.Now.Year) + 1); // Store the request timestamp Helper.StoreTime(LAST_REQUEST_TIMESTAMP_PPKEY, DateTime.Now); } #elif UNITY_ANDROID if (Instance != null) { return; // only allow one alert at a time } // Create a Unity game object to receive messages from native side Instance = new GameObject(RATING_DIALOG_GAMEOBJECT).AddComponent <MobileNativeRatingRequest>(); // Replace placeholder texts if any. var texts = new RatingDialogContent( content.Title.Replace(RatingDialogContent.PRODUCT_NAME_PLACEHOLDER, Application.productName), content.Message.Replace(RatingDialogContent.PRODUCT_NAME_PLACEHOLDER, Application.productName), content.LowRatingMessage.Replace(RatingDialogContent.PRODUCT_NAME_PLACEHOLDER, Application.productName), content.HighRatingMessage.Replace(RatingDialogContent.PRODUCT_NAME_PLACEHOLDER, Application.productName), content.PostponeButtonText, content.RefuseButtonText, content.RateButtonText, content.CancelButtonText, content.FeedbackButtonText ); // Show the Android rating request AndroidNativeUtility.RequestRating(texts, EM_Settings.RatingRequest); if (!IsDisplayConstraintIgnored()) { // Increment the number of requests used this year. SetAnnualUsedRequests(DateTime.Now.Year, GetAnnualUsedRequests(DateTime.Now.Year) + 1); // Store the request timestamp Helper.StoreTime(LAST_REQUEST_TIMESTAMP_PPKEY, DateTime.Now); } #else Debug.Log("Request review is not supported on this platform."); #endif }