JohnAnge Kernodle JohnAnge Kernodle - 2 months ago 21
Objective-C Question

UIAlertView button action?

I have an

UIAlertView
that shows with this code that asks you to rate the application in the appstore.

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Rate on the Appstore!"
message:@""
delegate:self
cancelButtonTitle:@"Later"
otherButtonTitles:@"OK", nil];
[alert show];
[alert release];


But I cannot figure out how to add an action to the OK button that takes you to the app in the AppStore.

Answer

How about this?

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
    if (buttonIndex != [alertView cancelButtonIndex]) {
        NSLog(@"Launching the store");
        //replace appname with any specific name you want
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"itms://itunes.com/apps/appname"]];
    } 
}