Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SKStoreReviewController is deprecated in iOS 18, and replacement is not accesible in MAUI. #21410

Closed
PureWeen opened this issue Oct 10, 2024 · 11 comments · Fixed by #21441 or #21750
Closed
Assignees
Labels
enhancement The issue or pull request is an enhancement
Milestone

Comments

@PureWeen
Copy link

Moved from dotnet/maui#25169

Description

Hello,

with iOS 18 it seems that Apple deprecated SKStoreReviewController. Now every plugin and call made from SKStoreReviewController are not working. There is a replacement with AppStore.requestReview(in: scene). But from MAUI it is inaccessible.

https://developer.apple.com/documentation/storekit/appstore/3954432-requestreview/

Steps to Reproduce

Create an application
on ios18 invoke

if (UIApplication
                            .SharedApplication?
                            .ConnectedScenes?
                            .ToArray<UIScene>()?
                            .FirstOrDefault(x => x.ActivationState == UISceneActivationState.ForegroundActive) is UIWindowScene windowScene)
                    {
                        SKStoreReviewController.RequestReview(windowScene);
                        return Task.CompletedTask;
                    }

see that application hangs.

same code on iOS 17.5 works, create a review popup or just passes quietly.

Link to public reproduction project repository

No response

Version with bug

8.0.91 SR9.1

Is this a regression from previous behavior?

No, this is something new

Last version that worked well

Unknown/Other

Affected platforms

iOS

Affected platform versions

iOS 18+

Did you find any workaround?

No

Relevant log output

No response

@rolfbjarne
Copy link
Member

AppStore.RequestReview looks like a really simple API, so we might be able to bind it manually.

I'll see what I can do.

@rolfbjarne rolfbjarne self-assigned this Oct 15, 2024
@rolfbjarne rolfbjarne added this to the Future milestone Oct 15, 2024
rolfbjarne added a commit that referenced this issue Oct 15, 2024
The existing Objective-C class to request an App Store review (SKStoreReviewController)
is deprecated in Xcode 16+, and it doesn't even work on the corresponding OS versions.

The replacement API is Swift-only, but luckily it's a very simple API (just a static
method), so it's possible to bind it manually.

This required a few other changes/improvements:

* Add support for Swift code in our runtime.

* Just to keep the changes to a minimum, bump the min OS version for legacy code
  to match the .NET min OS versions. This is because our build logic uses the legacy
  min versions when compiling native code (a more involved fix would be to update
  all the build logic to build native code to use the .NET min OS versions, but that's
  not the point of this PR, so I took the easy route).

I've tested the method locally, and it seems to work fine, but I've still marked
it as experimental for now. There are no unit tests because calling the method will
put up a dialog, which won't work correctly in unit tests.

Fixes #21410.
@rolfbjarne
Copy link
Member

We're binding this as an experimental API named StoreKit.AppStore.RequestReview(UIWindowScene).

@MerSpyro
Copy link

MerSpyro commented Oct 17, 2024

@rolfbjarne @PureWeen
Could you provide information when and where this fix will be available? Im not too sure where I'd go to look for this, in .net release, MAUI release or somewhere else?

@rolfbjarne thanks for this extremely swift binding of new API!

@rolfbjarne
Copy link
Member

@rolfbjarne @PureWeen Could you provide information when and where this fix will be available? Im not too sure where I'd go to look for this, in .net release, MAUI release or somewhere else?

This will be in an update to the iOS workload, most likely when we add support for Xcode 16.1 (which will probably happen soon after .NET 9 has been released, although this depends a bit on when exactly Apple makes Xcode 16.1 stable).

@tipa
Copy link

tipa commented Oct 17, 2024

Can the same be considered for the reloadAllTimelines() method?
I am currently using this workaround (in combination with an app extension written in Swift) but it adds quite a bit of boilerplate to my projects.

@rolfbjarne
Copy link
Member

Can the same be considered for the reloadAllTimelines() method? I am currently using this workaround (in combination with an app extension written in Swift) but it adds quite a bit of boilerplate to my projects.

I filed a suggestion for this: #21466

haritha-mohan pushed a commit that referenced this issue Oct 19, 2024
The existing Objective-C class to request an App Store review (SKStoreReviewController) is deprecated in Xcode 16+, and it doesn't even work on the corresponding OS versions.

The replacement API is Swift-only, but luckily it's a very simple API (just a static method), so it's possible to bind it manually.

This required a few other changes/improvements:

* Add support for Swift code in our runtime.

* Just to keep the changes to a minimum, bump the min OS version for legacy code to match the .NET min OS versions. This is because our build logic uses the legacy min versions when compiling native code (a more involved fix would be to update all the build logic to build native code to use the .NET min OS versions, but that's not the point of this PR, so I took the easy route). Fixes #10659.

I've tested the method locally, and it seems to work fine, but I've still marked
it as experimental for now. There are no unit tests because calling the method will
put up a dialog, which won't work correctly in unit tests.

Fixes #21410.
Fixes #10659.
@tipa
Copy link

tipa commented Nov 28, 2024

@rolfbjarne I tried the new API and it doesn't seem to work for me. It is documented that the review dialog is shown always in development mode, but when I call the method, nothing happens at all: no dialog, no crash, no logged error (that I could see) - both on macOS and iOS.

I then tried binding the method myself - using the same approach that is explained here:

@MainActor
@_cdecl("RequestReview")
@available(iOS 16, macCatalyst 16, *)
public func StoreKit_RequestReview(scene: UIWindowScene)
{
    AppStore.requestReview(in: scene)
}

And in my C# code:

[DllImport("__Internal", EntryPoint = "RequestReview")]
public static extern int RequestReview(IntPtr windowScene);

...

var scene = UIApplication.SharedApplication.ConnectedScenes.ToArray()
    .FirstOrDefault(x => x.ActivationState == UISceneActivationState.ForegroundActive);
if (scene is UIWindowScene windowScene) { RequestReview(windowScene.Handle); }

And using that code, the rating dialog shows reliably.

@rolfbjarne
Copy link
Member

@tipa that's strange, this code works for me:

var scene = UIApplication.SharedApplication.ConnectedScenes.ToArray()
				.FirstOrDefault (x => x.ActivationState == UISceneActivationState.ForegroundActive);
if (scene is UIWindowScene windowScene) {
	StoreKit.AppStore.RequestReview (windowScene);
}

Complete test project: ios-plain-80b52c1.zip

@tipa
Copy link

tipa commented Dec 3, 2024

@rolfbjarne I tested your project and it works. It now also works when I call the API from my iOS apps. I can't say yet, why this wasn't the case when I tested it last week.

However, I can still reproduce the problem on macOS. Can you have a look at my test project?
The review dialog only appears when I call the self-bound method.

reviewmacos.zip

@rolfbjarne
Copy link
Member

OK, I see what's happening.

Adding this to the csproj should work around it:

<ItemGroup>
  <ReferenceNativeSymbol Include="XamarinSwiftFunctions" SymbolType="ObjectiveCClass" />
</ItemGroup>

@rolfbjarne
Copy link
Member

@rolfbjarne I tested your project and it works. It now also works when I call the API from my iOS apps. I can't say yet, why this wasn't the case when I tested it last week.

However, I can still reproduce the problem on macOS. Can you have a look at my test project? The review dialog only appears when I call the self-bound method.

reviewmacos.zip

I've merged a fix for this, which will be included when we ship support for Xcode 16.2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement The issue or pull request is an enhancement
Projects
None yet
4 participants