jamesmontemagno / StoreReviewPlugin

Request app store reviews across Xamarin and Windows applications
MIT License
184 stars 24 forks source link

Feature Request: Detecting iOS requestReview #18

Closed JulesMoorhouse closed 3 years ago

JulesMoorhouse commented 3 years ago

This isn't a bug, It's a feature request.

The iOS [SKStoreReviewController requestReview] lacks any means of detecting whether the rating dialog has been shown. This is due to Apples limits on when the dialog an be shown. However, on StackOverflow there's a solution which counts the number of windows before and after showing the dialog. So some response can be derived. Granted this isn'e perfect.

You are allowed to ask for reviews and you are allowed to show the rating dialog. This method allows you to do one or the other at some point in your app.

Here's the Stackoverflow solution... https://stackoverflow.com/a/44137413

There is another solution further down saying it has been approved by Apple.

I would really like to see this added to the Plugin, if I were to submit a PR would it be accepted?

Here's the solution I've converted to c# I would take out the AppId and use it as a parameter and add in the MacOS code etc.


    public class AppReview : IAppReview
    {
        bool IsiOS103 => UIDevice.CurrentDevice.CheckSystemVersion(10, 3);

        /// <summary>
        /// Requests an app review.
        /// </summary>
        public Task RequestReviewRatingAsync()
        {
            // make sure we the current iOS version supports in app reviews
            if (IsiOS103)
            {
                var windowCount = 0;
                var afterWindowCount = 0;

                CoreFoundation.DispatchQueue.MainQueue.DispatchAsync(async () =>
                {
                    windowCount = GetWindowCount();

                    // Beware of PopupNavigationPopAsync which will close this
                    SKStoreReviewController.RequestReview();

                    // give the review controller some time to display the popup
                    await Task.Delay(1 * 1000);

                    afterWindowCount = GetWindowCount();

                });
                if (windowCount < afterWindowCount)
                {
                    // assume review popup showed instead of some other system alert
                    // for example show "thank you"

                }
                else
                {
                    OpenStoreReviewPage();
                }
            }
            else
            {
                OpenStoreReviewPage();
            }

            return Task.CompletedTask;
        }

        /// <summary>
        /// Opens the store review page.
        /// </summary>
        public void OpenStoreReviewPage()
        {
            var appId = GetAppID();

            var url = $"itms-apps://itunes.apple.com/app/id{appId}?action=write-review";
            try
            {
                UIApplication.SharedApplication.OpenUrl(new NSUrl(url));
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Unable to launch app store: " + ex.Message);
            }
        }

        /// <summary>
        /// Returns the app id
        /// </summary>
        /// <returns></returns>
        public string GetAppID()
        {
            return "1234";
        }

        private int GetWindowCount()
        {
            var windowCount = UIApplication.SharedApplication.Windows.Count();
            return windowCount;
        }
    }
}
saamerm commented 3 years ago

@JulesMoorhouse according to the answer you shared, that feature is only available until iOS 11, and it doesn't seem like anyone verified that it works in production. Am I right?

JulesMoorhouse commented 3 years ago

@saamerm as mentioned, in this answer, guy saying he’s had no problem. https://stackoverflow.com/a/53545977/450456 with pretty much identical code.

No there’s no additional iOS version requirement, other than the 10.3 actually in the plug-in already.

jamesmontemagno commented 3 years ago

I wouldn't want to add in any code like this. Any hack like this is a nightmare. Only official apis. Thanks for the recommendation though.