I am not proud of this hack, but I didn't want to lose all of the functionality provided by default for phone numbers. As a result, I was able to get things to work via the following:
If you are getting an error in your log that says "Attempt to present ... on ... whose view is not in the window hierarchy", it means that your `window.rootViewController.view` is not in the window's hierarchy. This is likely the case because you have presented something full screen modal on top of it. In order to get past this, find all of the full screen modals in the view controller hierarchy up to your screen with your `UITextView` and change the `modalPresentationStyle` on the presented view controller to `.OverFullScreen`.
Hopefully, this gets you past the first issue, but then, when you try again, you will get a new error in your log that says "Attempt to present ... on ... which is already presenting".
In order to get past this one, I followed nate.m's lead and overroad the `presentViewController` method in my rootViewController class. (Mine is custom, but if you have something like a `UINavigationController` here, I imagine that you are going to have to subclass it.) Then, in this overridden implementation, walk through the `presentedViewControllers` until you reach one that is `nil`. When you do, present from that view controller. My implementation looks like this:
override func presentViewController(viewControllerToPresent: UIViewController, animated flag: Bool, completion: (() -> Void)?) {
guard let alertController = viewControllerToPresent as? UIAlertController else {
super.presentViewController(viewControllerToPresent, animated: flag, completion: completion)
return
}
var presentingVC: UIViewController = self
while let presentedVC = presentingVC.presentedViewController {
presentingVC = presentedVC
}
presentingVC.presentViewController(alertController, animated: flag, completion: completion)
}
Again, I am not proud of this, but it was the only thing that I could figure out in order to get system behavior for the phone number links.
I would really love to know what UIKit is doing in this instance such that it is trying to present from `window.rootViewController`?
Let me know if this works for you, or if you find something better.
Hope this helps.