Link detection Crash
In reviewing a crash log for a recently published app, I ran across a scenario where a user could reproducibly force a crash by using a long press on a link in a UITextView.
- Occurs on iOS 9.
- UITextView on a presented view controller.
- Two consecutive long presses on a detected link in the UITextView.
On the first long press, I see the warning:
Attempt to present <_UIRotatingAlertController: …
The second long press causes the crash with the signature:
Assertion failure in -[UITextView startInteractionWithLinkAtPoint:]
The workaround
Some searching led me to the following thread which discussed the specific crash I was seeing (though my case was a web URL) along with some suggested workarounds:
Crash on UITextView phone number selection
I ended up implementing the shouldInteractWithURL method of the UITextViewDelegate protocol. I return NO from this method and handle the URL myself:
- (BOOL)textView:(UITextView *)textView shouldInteractWithURL:(NSURL *)URL inRange:(NSRange)characterRange { if([[UIApplication sharedApplication] canOpenURL:URL]){ [[UIApplication sharedApplication] openURL:URL]; } // Don't let UITextView handle the URL interaction. return NO; }
Problem solved.