21 Replies
      Latest reply on Aug 10, 2016 7:09 AM by mw4439
      wadedunk Level 1 Level 1 (0 points)

        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

        • Re: Crash on UITextView phone number selection
          raver99.3gp Level 1 Level 1 (0 points)

          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.

          • Re: Crash on UITextView phone number selection
            danielct Level 1 Level 1 (0 points)

            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

            • Re: Crash on UITextView phone number selection
              chad1120 Level 1 Level 1 (0 points)

              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: ''

              • Re: Crash on UITextView phone number selection
                Phamer55 Level 1 Level 1 (0 points)

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

                • Re: Crash on UITextView phone number selection
                  andr3a88 Level 1 Level 1 (0 points)

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

                  • Re: Crash on UITextView phone number selection
                    treeDow Level 1 Level 1 (0 points)

                    Have you find some way to fix it?

                    • Re: Crash on UITextView phone number selection
                      treeDow Level 1 Level 1 (0 points)

                      I have to

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

                      {

                           [[UIApplication sharedApplication] openURL:URL];

                          return NO;

                      }

                      • Re: Crash on UITextView phone number selection
                        nate.m Level 1 Level 1 (0 points)

                        I saw this for "event" links (e.g. "4pm") from UITextView with dataDetectorTypes set to UIDataDetectorTypeAll.  The work around I used was to override -[presentViewController:animated:completion:] in my root view controller.  Here's the gist of it:

                         

                        - (void)presentViewController:(UIViewController *)viewControllerToPresent animated:(BOOL)flag completion:(void (^)(void))completion {
                            if ([viewControllerToPresent isKindOfClass:UIAlertController.class] && !self.view.window) {
                                UIViewController *vc = <code to find the top most view controller>;
                                [vc presentViewController:viewControllerToPresent animated:flag completion:completion];
                            } else {
                                [super presentViewController:viewControllerToPresent animated:flag completion:completion];
                            }
                        }
                        
                        • Re: Crash on UITextView phone number selection
                          chrismorris Level 1 Level 1 (0 points)

                          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.

                          • Re: Crash on UITextView phone number selection
                            ichdertom Level 1 Level 1 (0 points)

                            In my case a simple clean did the job.

                            • Re: Crash on UITextView phone number selection
                              steipete Level 1 Level 1 (10 points)

                              We've recently fixed this after stumbling on this issue in our PSPDFKit.

                               

                              The fix dynamically applies and removes a workaround. This is better than brutally overriding presentViewController as this might swallow valid bugs.

                               

                              https://gist.github.com/steipete/b00fc02aa9f1c66c11d0f996b1ba1265

                               

                              We also reported this as rdar://26295020 to Apple. Please dupe!