jamesmontemagno / StoreReviewPlugin

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

Use the new `requestReview(in: uiWindowScene)` for iOS 14 and above #32

Closed michaldivis closed 2 years ago

michaldivis commented 2 years ago

Feature Request: new iOS requestReview(in:)

Use the new requestReview(in: uiWindowScene) that's available since iOS 14.0.

Why

The implementation currently used in this plugin (requestReview()) is deprecated since iOS 14.0.

Proposal

I'd like to propose using the new variation of the requestReview(in: uiWindowScene) method.

It shouldn't be a big change (hopefully), I've already tried to implement the new way and it seems to be working.

Here's a possible implementation (I'm not iOS expert so I apologize if the implementation shown in the examples is wrong):

using StoreKit;
using UIKit;

public void RequestReview()
{
    var isIos14OrAbove = UIDevice.CurrentDevice.CheckSystemVersion(14, 0);
    if (isIos14OrAbove)
    {
        var scene = UIApplication.SharedApplication.KeyWindow.WindowScene;

        //another option (I'm not sure which to use):
        //var scene = UIApplication.SharedApplication.Delegate.GetWindow()?.WindowScene;

        if (scene is null)
        {
            //handle the scene being null here
            return;
        }

        SKStoreReviewController.RequestReview(scene);
    }
    else
    {
        SKStoreReviewController.RequestReview();
    }
}
saamerm commented 2 years ago

@michaldivis Good catch!

michaldivis commented 2 years ago

@saamerm Wow, that was really quick! Thanks so much!

jamesmontemagno commented 2 years ago

I think if they aren't using scenes then we use the old mechanism i am cool with that.

jamesmontemagno commented 2 years ago

I see that addressed in PR nice!