Crash on UITextView phone number selection

Seems that iOS 9 has some bug with presenting alert after UITextView phone number selection. This occurs only if this UITextView is on the view controllers which has been modally presented over root view controller.

Log:

Warning: Attempt to present <_UIRotatingAlertController: 0x1866aa00> on <HomeViewController: 0x17ad8e00> whose view is not in the window hierarchy!

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

Replies

I can confirm that this is also happening to me. I made a very small test app to verify this:

- having 2 viewcontrollers: one root which presents the other one modally

- have a UITextView on the presented viewcontroller with phone number detection

- tapping once brings you the warning mentioned above,

- tapping the second time crashes the app.


I implemented a workaround, to manually open the system "telprompt", but would like to know if this is an iOS 9 bug or are there changes to the framework that I am not aware yet.

Please file a bug report and attach your test app so that we can investigate it.

I've already filed bug report with test app (#22836977)

What's the status of this problem? I also experience the same problem. I hope this is solved already.

This also happens with Links. Happens when one long-presses a link and then keep holding.


Also see this message in the console: `Warning: Attempt to present <_UIRotatingAlertController: 0x7fdbb9955800> on <UITabBarController: 0x7fdbb8c9bf50> whose view is not in the window hierarchy!

*** Assertion failure in -[UITextView startInteractionWithLinkAtPoint:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit_Sim/UIKit-3505.16/UITextView_LinkInteraction.m:377`


note: Not implementing any UITextView delegate methods

I am experiencing the same behavior. It is working correctly for iPad, but not iPhone. I have not tested iPod. On the iPhone 6s, short press and 3D Touch works on phone numbers, but it has the same issue with long press.


Here is what I found:

  • Phone numbers presented on the root view controller work on all devices tested.
  • Phone numbers presented in a UITextView on views other than the root view are throwing the exception.
  • Short press on all devices is working correctly.
  • 3D Touch press on iPhone 6s is working correctly.
  • iPad is working correctly.
  • Long press on iPhones (tested:5c,5s,6s) are failing.


First Try: Warning

2015-09-29 14:00:33.013 PhoneNumberTapTest[5078:302812] Warning: Attempt to present <_UIRotatingAlertController: 0x7f9044882c00> on <PhoneNumberTapTest.ViewController: 0x7f9043e232c0> whose view is not in the window hierarchy!


Second Try: Exception

2015-09-29 14:01:55.149 PhoneNumberTapTest[5078:302812] *** Assertion failure in -[UITextView startInteractionWithLinkAtPoint:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit_Sim/UIKit-3505.16/UITextView_LinkInteraction.m:377

2015-09-29 14:01:55.155 PhoneNumberTapTest[5078:302812] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: ''

Hi raver99.3gp, Are you able to share your workaround?

Yes.


I am doing something like this:


if([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"telprompt://"]]){

NSURL* phoneNumberURL = [self formatedUrlFromPhoneNumberString:phoneNumberString];

[[UIApplication sharedApplication] openURL:phoneNumberURL];

}


Which presents a UIAlertView style dialog that asks the user if he wants to call that number.

This works with phonenumbers, other types of URL should be handled accordingly.

I am also waiting on a fix. I need this fix for all link types. It was working perfectly fine in iOS8 and it still does. Upgrade to iOS9, no bueno.


Hope there is a fix on the way!

I ended up simply implementing UITextViewDelegate and that fixed the crashes my side:


func textView(textView: UITextView, shouldInteractWithURL URL: NSURL, inRange characterRange: NSRange) -> Bool {
    //Insert presentation of SFSafariViewController with URL here
    return false
}

I confirm seeing this issue with our app on iOS 9 long press (iOS 8 okay). Has an official bug been logged?

I have the same issue on iPad after phone number selection on UITextView, on iPhone works fine.

Have you find some way to fix it?

I have to

- (BOOL)textView:(UITextView *)textView shouldInteractWithURL:(NSURL *)URL inRange:(NSRange)characterRange

{

[[UIApplication sharedApplication] openURL:URL];

return NO;

}

Wade, can you provide a link to your sample app? I'd like to file a report as well.