TL;DR: Is there some way on iOS to detect the presence/display of the Storekit App Rating dialog added in iOS 10.3?
I\'ve recently added support for the new app rati
Your question got me thinking, and it is easier than I would have thought.
My first thought was to check UIWindow
related things - a quick look at the documentation revealed, that there are UIWindow
related notifications - great! I made a quick project, subscribed to all of them and presented the review controller. This popped up in the logs :
method : windowDidBecomeVisibleNotification:
object -> ; layer = >
So in order to detect if the review controller was shown, you'd need to subscribe to a notification and inspect it's object
property to find out its class :
- (void)viewDidLoad {
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(windowDidBecomeVisibleNotification:)
name:UIWindowDidBecomeVisibleNotification
object:nil];
}
- (void)windowDidBecomeVisibleNotification:(NSNotification *)notification {
if ([notification.object isKindOfClass:NSClassFromString(@"SKStoreReviewPresentationWindow")]) {
NSLog(@"the review request was shown!");
}
}
Now bear in mind that SKStoreReviewPresentationWindow
is not publicly accessible - so you can't simply write [SKStoreReviewPresentationWindow class]
, and tricking the system by using NSClassFromString
is just that - tricking the system. Unfortunately the other most interesting notification, UIWindowDidResignKey
, was not issued - I hoped that the main window would resign, but unfortunately not. Some further debugging also showed that the main window remains key and not hidden. You could of course try comparing the notification.object
to [UIApplication sharedApplication].window
, but there were also other windows being shown - UITextEffectsWindow
and UIRemoteKeyboardWindow
, especially when the alert was first shown, and both of them are also not public.
I'd consider this solution a hack - it is prone to changes by Apple that will break it. But most importantly, this could be grounds for rejection during review, so use at your own risk. I tested this on iPhone 7+ Simulator, iOS 10.3, Xcode 8.3.2
Now, since we now know that it is kinda possible to detect if the review controller was shown, a more interesting problem is how to detect that it was NOT shown. You'd need to introduce some timeout after which you'd do something because the alert was not shown. This can feel like your app hanged, so it would be a bad experience for your users. Also, I noticed that the review controller is not shown immediately, so it even makes more sense why Apple doesn't recommend showing it after pressing a button.