ios8 iPad uiwebview crashes while displaying popover when user taps drop down list HTML select tag

前端 未结 5 1674
生来不讨喜
生来不讨喜 2020-11-30 21:00

On ios8 and iPad if a uiwebview is displaying a HTML page containing a drop down list

eg this page http://www.w3schools.com/tags/tryit.asp?filename=tryh

5条回答
  •  醉话见心
    2020-11-30 21:27

    I have decreased the probability of occurrence of crash in this way.. Used javascript code and native ios

    Web Side code changes

    1. Register a 'click' event listener to your html component(drop down).
    2. In the call back method send notification to native code. ex : "window.location='fromJavaScript://PopoverIssue'; "
    3. It will call uiwebviews shouldStartLoadWithRequest

    Native Side code changes

    1. Implement UIPopoverPresentationControllerDelegate protocol on viewcontroller which has uiwebview and over ride popoverPresentationControllerShouldDismissPopover popoverPresentationControllerDidDismissPopover
    2. put below code in shouldStartLoadWithRequest method of uiwebview for the above click notification
      [[UIApplication sharedApplication] beginIgnoringInteractionEvents];
          self.popoverPresentationController = self.presentedViewController.popoverPresentationController;
          self.existedPopoverDelegate = [self.popoverPresentationController delegate];
          self.popoverPresentationController.delegate = self;
          dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0);
          dispatch_async(queue, ^{
              int64_t delay = 2.0;
              dispatch_time_t time = dispatch_time(DISPATCH_TIME_NOW, delay * NSEC_PER_SEC);
              dispatch_after(time, dispatch_get_main_queue(), ^{
                  if([[UIApplication sharedApplication] isIgnoringInteractionEvents])
                  {
                      [[UIApplication sharedApplication] endIgnoringInteractionEvents];
                  }
              });
          });
    3. implement the overridden protocol methods as follows

      • (BOOL)popoverPresentationControllerShouldDismissPopover:(UIPopoverPresentationController *)popoverPresentationController { [self.existedPopoverDelegate popoverPresentationControllerShouldDismissPopover:popoverPresentationController]; return YES; }

      • (void)popoverPresentationControllerDidDismissPopover:(UIPopoverPresentationController *)popoverPresentationController { [self.existedPopoverDelegate popoverPresentationControllerDidDismissPopover:popoverPresentationController]; dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0); dispatch_async(queue, ^{ int64_t delay = 2.0; dispatch_time_t time = dispatch_time(DISPATCH_TIME_NOW, delay * NSEC_PER_SEC); dispatch_after(time, dispatch_get_main_queue(), ^{ if([[UIApplication sharedApplication] isIgnoringInteractionEvents]) { [[UIApplication sharedApplication] endIgnoringInteractionEvents]; } }); }); }

Hope it will help to decrease the crash occurrence .

提交回复
热议问题