arashpayan / appirater

A utility that reminds your iPhone app's users to review the app.
http://arashpayan.com/blog/2009/09/07/presenting-appirater/
4.62k stars 856 forks source link

Crash with [UIAlertController dismissWithClickedButtonIndex:animated:]: unrecognized selector sent to instance [Fix provided] #266

Closed nickbit closed 6 years ago

nickbit commented 6 years ago

Hi Arash,

Crash occurs in Appirater.m:570

- (void)hideRatingAlert {
    if ([self isRatingAlertVisible]) {
        if (_debug)
            NSLog(@"APPIRATER Hiding Alert");
        [self.ratingAlert dismissWithClickedButtonIndex:-1 animated:NO];
    }   
}

Reason is that dismissWithClickedButtonIndex:animated is valid for UIAlertView but not for UIAlertController.

Here is a fix:

- (void)hideRatingAlert {
    if ([self isRatingAlertVisible]) {
        if (_debug)
            NSLog(@"APPIRATER Hiding Alert");
            if ([self.ratingAlert respondsToSelector:@selector(dismissWithClickedButtonIndex:animated:)]) {
                [self.ratingAlert dismissWithClickedButtonIndex:-1 animated:NO];
            } else {
                [self.ratingAlert dismissViewControllerAnimated:NO completion:nil];
            }
    }   
}
jamescahall commented 6 years ago

I've received crash alerts for the same issue. Please fix.

jamescahall commented 6 years ago

Nickbit, do you have a fork for this? We really need to get this fix out to users right away as its affecting a ton of users on apps.

arashpayan commented 6 years ago

Thank you for the diagnosis and solution @nickbit. @jamescahall, I'll be releasing an update with this fix in an hour or two.

arashpayan commented 6 years ago

I released this in 2.3.1.