My app writes out a small HTML file to the user's temporary cache. This file points to the our login in server, and contains the user name and password and a redirect to the actual URL I want the user to go to.
Everything works OK but within the methods of the UIWebView I need to detect what URL I eventually end up on because I must parse this URL to determine whether to show or hide navigation.
Everything works BUT I cannot detect the actual URL that the page ends up on - I just keep getting the filePath.
My header is as so:
#import <UIKit/UIKit.h>
@interface ViewControllerApprovals : UIViewController <UIWebViewDelegate> {
}
@property(nonatomic, retain) IBOutlet UIWebView *webView;
@property(nonatomic, retain) NSURLRequest *currentRequest;
@property(nonatomic, strong) NSString *requestType;
@property(nonatomic, strong) NSString *pathToFile;
@end
And my implementation file:
#import "ViewControllerApprovals.h"
#import "ContactsDatabase.h"
#import "UserDefaults.h"
#import "SettingsViewController.h"
@interface ViewControllerApprovals ()
@end
@implementation ViewControllerApprovals
- (id)initWithNibName:(NSString *)nibNameOrNil
bundle:(NSBundle *)nibBundleOrNil {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
self.view.backgroundColor =
[[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"sos.png"]];
if (self) {
}
return self;
}
- (void)viewDidAppear:(BOOL)animated {
}
- (void)viewDidLoad {
[self setEdgesForExtendedLayout:UIRectEdgeNone];
self.webView.delegate = self;
NSURL *targetURL = [NSURL fileURLWithPath:self.pathToFile];
NSURLRequest *tmpRequest = [NSURLRequest requestWithURL:targetURL];
[self.webView loadRequest:tmpRequest];
}
- (BOOL)webView:(UIWebView *)webView
shouldStartLoadWithRequest:(NSURLRequest *)request
navigationType:(UIWebViewNavigationType)navigationType {
self.currentRequest = request;
[self hideNavigationBar:request];
return YES;
}
#pragma mark - Hide Navigation Bar
- (void)hideNavigationBar:(NSURLRequest *)pRequest {
NSString *currentURL = self.webView.request.URL.absoluteString;
NSURL *url = pRequest.URL;
NSString *urlString = [url absoluteString];
NSString *nsfURL = @"#approvalPage";
if ([urlString rangeOfString:nsfURL].location == NSNotFound) {
[self.navigationController setNavigationBarHidden:FALSE animated:YES];
} else {
[self.navigationController setNavigationBarHidden:TRUE animated:YES];
}
}
@end