-(IBAction)btnclick:(id)sender{
NSURL *fileURL = [NSURL fileURLWithPath:[@"/Users/new1/Desktop/temp.txt" stringByExpandingTildeInPath]];
NSError *error = nil;
NSString *fileContentsString = [NSString stringWithContentsOfURL:fileURL
encoding:NSUTF8StringEncoding
error:&error];
if (!fileContentsString) {
NSLog(@"Error reading file");
}
NSString *url;
if (![[[[txtFld stringValue] componentsSeparatedByString:@"//"] objectAtIndex:0] isEqualToString:@"http:"]){
url = [[[txtFld stringValue] componentsSeparatedByString:@"."] objectAtIndex:0];
}
else{
url = [[[txtFld stringValue] componentsSeparatedByString:@"."] objectAtIndex:1];
}
NSRange result = [fileContentsString rangeOfString:url];
if (result.location == NSNotFound) {
NSLog(@"URL not found in file");
NSAlert *alrt = [[NSAlert alloc] init];
NSString *alrtstr = [NSString stringWithFormat:@"Not Authorise person to open : %@",[txtFld stringValue]];
[alrt setMessageText:alrtstr];
[alrt runModal];
NSLog(@"btn clicked ");
}
else{
NSLog(@"URL found in file : %@",[txtFld stringValue]);
if (![[[[txtFld stringValue] componentsSeparatedByString:@"//"] objectAtIndex:0] isEqualToString:@"http:"]){
[webVw setMainFrameURL:[NSString stringWithFormat:@"http://%@",[txtFld stringValue]]];
}
else{
[webVw setMainFrameURL:[txtFld stringValue]];
}
}
}
-(IBAction)webView:(WebView *)sender didReceiveTitle:(NSString *)title forFrame:(WebFrame *)frame{
NSString *currentURL = [webVw stringByEvaluatingJavaScriptFromString:@"location.href;"];
NSLog(@"%@",currentURL);
[txtFld setStringValue:currentURL];
}