1

I'm facing weird crash while long pressing and then clicking a link inside UITextView. Below is my code for handling touch event on link.

    func textView(_ textView: UITextView, shouldInteractWith URL: URL, in characterRange: NSRange) -> Bool {
    let termsAndConditions : TRTermsAndConditionsViewController = TRTermsAndConditionsViewController(nibName: "TRTermsAndConditionsViewController", bundle: nil)
    let navigationtermsAndConditions = TRBaseNavigationViewController(rootViewController: termsAndConditions)
    self.present(navigationtermsAndConditions, animated: true, completion: nil)
    return false
}

I'm getting below error:

*** Assertion failure in -[TRADFRI.TRTextViewNonEditable startInteractionWithLinkAtPoint:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit/UIKit-3512.29.5/UITextView_LinkInteraction.m:377

I googled a lot and gone through these links as well link1 link2 but didn't get any success. I have tried solution given by "Sukhrob" and "ryanphillipthomas" on link1 and solution given by "nate.m" and "chrismorris" on link2. More weird thing is that i'm getting this crash on devices that support 3D touch like iPhone 6S, iPhone 6S Plus(with iOS 9 or above). Can anybody help me out for this issue.

Varun Mehta
  • 1,733
  • 3
  • 18
  • 39
  • According to the provided link, it is a iOS9 (nad 10?) bug. It also provides a workaround. Did you try this and it doesn't work for you? In this case, maybe edit the question with what you actually have tried and what is not working. – shallowThought Jan 20 '17 at 07:06

1 Answers1

1

At last i resolved this issue by getting some help from this link

So i have removed the link attribute from NSAttributedString and make use of underline attribute only. By making use of tap gesture , i'm detecting the index of character on which user is tapping and if that index lying in my hyperlink range i'm opening the URL.

Community
  • 1
  • 1
Varun Mehta
  • 1,733
  • 3
  • 18
  • 39