Ok, so I found something weird and I have a workaround in place, but can somebody tell me where I'm going wrong here?
As you can see below, the delegate callback has been removed, and a timer put in its place.
*With a timer, the delegate callback works and the 'WebViewController' dismisses.
*Without a timer, the delegate callback works but the call to the UI element fails i.e. the 'WebViewController' doesn't dismiss (Modal view controller).
I suspect it's due to the fact that the sendSync method goes off on it's own thread for a while before it finishes. Right?
DELEGATE
----------
I have tested the following. These are facts.
1)Does the object your dismissing have the same memory address, before and after presenting/dismissing? i.e. is it the same object?
YES
2)Is the parent losing it's child?
NO
3)Are you using a depracated method?
NO
4)Are you calling dismiss from the parent?
YES
As you can see below, the delegate callback has been removed, and a timer put in its place.
*With a timer, the delegate callback works and the 'WebViewController' dismisses.
*Without a timer, the delegate callback works but the call to the UI element fails i.e. the 'WebViewController' doesn't dismiss (Modal view controller).
I suspect it's due to the fact that the sendSync method goes off on it's own thread for a while before it finishes. Right?
Code:
-(BOOL)verifyRequest:(NSURLRequest*)theRequest
{
[self showProgressHudInView:self.view withText:@"Verifying Priveledges."];
NSHTTPURLResponse *response; NSError *error;
if ([[theRequest.URL description] rangeOfString:@"ticket=ST"].location != NSNotFound)
{
[NSURLConnection sendSynchronousRequest:theRequest
returningResponse:&response
error:&error];
}
if ([response statusCode] == 403)
{
[NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(fireDelegateForStoppingDueToInsufficientPrivileges) userInfo:nil repeats:NO];
return NO;
// if ([self.delegate conformsToProtocol:@protocol(WebViewControllerDelegate)])
// {
// [self.delegate webViewController:self
// wasStoppedForReason:@"This device is currently restricted to Administrators only. Please contact an administration for more information."];
// }
// return NO;
}
else if (error)
{
// if ([self.delegate conformsToProtocol:@protocol(WebViewControllerDelegate)])
// {
// [self.delegate webViewControllerDidFailLoadCheck:self withError:error];
// }
// return NO;
[NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(fireDelegateForStoppingDueToFailureToCheckPriviledges) userInfo:nil repeats:NO];
return NO;
}
return YES;
}
Code:
-(void)fireDelegateForStoppingDueToInsufficientPrivileges
{
if ([self.delegate conformsToProtocol:@protocol(WebViewControllerDelegate)])
{
[self.delegate webViewController:self
wasStoppedForReason:@"This device is currently restricted to Administrators only. Please contact an administration for more information."];
}
}
-(void)fireDelegateForStoppingDueToFailureToCheckPriviledges
{
if ([self.delegate conformsToProtocol:@protocol(WebViewControllerDelegate)])
{
[self.delegate webViewControllerDidFailLoadCheck:self withError:nil];
}
}
DELEGATE
Code:
-(void)webViewController:(WebViewController *)theController wasStoppedForReason:(NSString *)theReason
{
NSLog(@"Is Main thread: %i", [NSThread isMainThread]);
if (self.progressHud) [self hideProgressHudView];
[theController dismissViewControllerAnimated:NO completion:^{
NSLog(@"Dismiss block called.");
[[[UIAlertView alloc] initWithTitle:@"Insufficient Privileges"
message:theReason
delegate:nil
cancelButtonTitle:@"Dismiss"
otherButtonTitles:nil, nil] show];
}];
}
----------
I have tested the following. These are facts.
1)Does the object your dismissing have the same memory address, before and after presenting/dismissing? i.e. is it the same object?
YES
2)Is the parent losing it's child?
NO
3)Are you using a depracated method?
NO
4)Are you calling dismiss from the parent?
YES