-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathBPInfoViewController.m
54 lines (43 loc) · 1.69 KB
/
BPInfoViewController.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#import "BPInfoViewController.h"
@implementation BPInfoViewController
@synthesize webView=_webView, url;
- (void)viewDidLoad {
[super viewDidLoad];
_webView.delegate = self;
self.title = @"Info";
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Done" style:UIBarButtonItemStyleDone target:self action:@selector(closeInfoView:)];
NSBundle *bundle = [NSBundle mainBundle];
NSString * urlPathString;
if (urlPathString = [bundle pathForResource:@"info" ofType:@"html" inDirectory:@"www"]){
[_webView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:urlPathString]
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:20.0]];
}
}
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
NSLog(@"expected:%d, got:%d", UIWebViewNavigationTypeLinkClicked, navigationType);
if (navigationType == UIWebViewNavigationTypeLinkClicked) {
self.url = request.URL;
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Open Link in Safari" message:[request.URL absoluteString] delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK", nil];
[alert show];
[alert release];
return NO;
}
return YES;
}
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {
if (buttonIndex == 1) {
[[UIApplication sharedApplication] openURL:url];
}
}
-(void)closeInfoView:(id)sender {
[self.navigationController dismissModalViewControllerAnimated:YES];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
- (void)dealloc {
[_webView release];
[super dealloc];
}
@end