You don’t actually need pathAlert.delegate = self
. You’ve already set the delegate in the initWithTitle:message:delegate:cancelButtonTitle:otherButtonTitles:
method call.
In your .h
file, you need to do this:
@interface YourViewControllerName : UIViewController <UIAlertViewDelegate>
And in the .m
file add this method:
- alertView:(id)alert didDismissWithButton:(int)index {
[[UIpplication sharedApplication] openURL:[NSURL URLWithString:@"foo"];
}
Alternatively, and possibly better might be to give the user the option of “Ok” to be redirected or “Cancel” to not navigate to that page. In which case, you need to create the alert as such:
UIAlertView *patchAlert = [[UIAlertView alloc] initWithTitle:@""
message:@"After clicking `OK` you will be redirected to Cydia"
delegate:self
cancelButtonTitle:@"Cancel"
otherButtonTitles:@"OK", nil];
Then, you can modify the handle method as such:
- alertView:(id)alert didDismissWithButton:(int)index {
if(index == 1) {
[[UIpplication sharedApplication] openURL:[NSURL URLWithString:@"foo"];
}
}
Now the URL
is only opened if they click “OK”, otherwise nothing happens.
solved Open a link when alert ok button is pressed [closed]