OK, after a lot of trial and error, I was able to fix the crash. It just amounted to commenting out various lines of code to see what made the crash go away. Here is an approximation of the original code:
-(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
if (self.appUrlNameSpace && [request.URL.absoluteString hasPrefix:self.appUrlNameSpace])
{
BOOL success = ([request.URL.absoluteString rangeOfString:self.failureUrlComponent].location != NSNotFound);
if (success)
{
NSString *responseString = [[NSString alloc]initWithData:response.HTTPBody encoding:NSUTF8StringEncoding];
responseItems = [[NSDictionary alloc]initWithHTTPPostResponse:responseString];
NSLog(@"Returned items %@", responseItems);
[self.delegate dismissViewControllerAnimated:NO completion:^{
. . .
}];
}
else
{
. . .
}
return NO;
}
else if ( . . .)
{
}
return YES;
}
The key finding was that disabling the dismissal of the view inside the webView:shouldStartLoadingWithRequest: was what prevented the crash. The code in the completion block did not need to be delayed, so I moved that to execute immediately (but this had no bearing on whether the crash occurred or not). So, I rearranged the code as follows such that dismissing the view does not occur directly from the UIWebView delegate callback, and magically the crash was gone.
-(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
if (self.appUrlNameSpace && [request.URL.absoluteString hasPrefix:self.appUrlNameSpace])
{
BOOL success = ([request.URL.absoluteString rangeOfString:self.failureUrlComponent].location != NSNotFound);
if (success)
{
NSString *responseString = [[NSString alloc]initWithData:response.HTTPBody encoding:NSUTF8StringEncoding];
responseItems = [[NSDictionary alloc]initWithHTTPPostResponse:responseString];
NSLog(@"Returned items %@", responseItems);
. . . /* Code that was originally in the completion block */
/* Delaying dismissal somehow prevents crash */
long delay = dispatch_time(DISPATCH_TIME_NOW, 0.1 * NSEC_PER_SEC);
dispatch_after( delay, dispatch_get_main_queue(), ^{
[self.delegate dismissViewControllerAnimated:NO completion:nil];
});
}
else
{
. . .
}
return NO;
}
else if ( . . .)
{
}
return YES;
}
I have no idea why this would make any difference, or why this crash only occurred on certain (older) iPad models, but hopefully this helps someone in the future.
Post
Replies
Boosts
Views
Activity
Submitted feedback: FB13429408