Basically I'm trying intercept taps on links to a remote file and instead open a local version that I already have stored.
I'm able to get to the action of the link after it is tapped, but I can't figure out how to stop it from executing the default behavior while keeping the URL intact.
Here's the relevant code:
- (void)pdfScrollViewTap:(UITapGestureRecognizer *)gestureRecognizer
{
Annot *annotation;
@try {
// If they are clicking an annotation, we don't want to process this
[self.pdfView DocLockRead];
CGPoint down = [gestureRecognizer locationInView:self.pdfView];
annotation = [self.pdfView GetAnnotationAt:down.x y:down.y];
}
@catch (NSException *exception) {
// something is wrong with the annotation, it may not be selected properly
}
@finally {
[self.pdfView DocUnlockRead];
}
// This is how we find out a Link was tapped
if ([annotation IsValid]) {
if (annotation.GetType == e_Link) { // Its a link
Link *link = [[Link alloc] initWithAnn:annotation]; // here's the link
Action *action = link.GetAction; // links have an action, heres that
if ([action IsValid]) { // hopefully its valid
if (action.GetType == e_URI) { // URI is the URL the link points to
if ([self.delegate respondsToSelector:@selector(shouldOpenURLforLinkAnnotation:withViewController:)]) { // Check if the delegate implements this
NSString *origURL = [action.GetSDFObj FindObj:@"URI"].GetAsPDFText;
if (![self.delegate shouldOpenURLforLinkAnnotation:origURL withViewController:self]) {
// The delegate handles finding and opening the local file
// Find a away to disable or stop the action here
}
}
}
}
}
return;
}
}
I've tried simply removing the action with:
[link RemoveAction];
This works the first time, but as expected the action is never called again after removing it.