[ios] Open links from About in Safari

This commit is contained in:
Alex Zolotarev 2014-05-27 18:51:38 +08:00 committed by Alex Zolotarev
parent e5e83c7a8f
commit 0c7577d015
3 changed files with 16 additions and 1 deletions

View file

@ -1,9 +1,11 @@
#import <UIKit/UIKit.h>
@interface WebViewController : UIViewController
@interface WebViewController : UIViewController <UIWebViewDelegate>
@property (nonatomic) NSURL * m_url;
@property (nonatomic) NSString * m_htmlText;
// Set to YES if external browser should be launched
@property (nonatomic) BOOL openInSafari;
- (id)initWithUrl:(NSURL *)url andTitleOrNil:(NSString *)title;
- (id)initWithHtml:(NSString *)htmlText baseUrl:(NSURL *)url andTitleOrNil:(NSString *)title;

View file

@ -36,6 +36,7 @@
// webView.scalesPageToFit = YES;
webView.autoresizesSubviews = YES;
webView.autoresizingMask = (UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth);
webView.delegate = self;
if (self.m_htmlText)
[webView loadHTMLString:self.m_htmlText baseURL:self.m_url];
@ -50,4 +51,15 @@
return YES;
}
-(BOOL)webView:(UIWebView *)inWeb shouldStartLoadWithRequest:(NSURLRequest *)inRequest navigationType:(UIWebViewNavigationType)inType
{
if (self.openInSafari && inType == UIWebViewNavigationTypeLinkClicked)
{
[[UIApplication sharedApplication] openURL:[inRequest URL]];
return NO;
}
return YES;
}
@end

View file

@ -150,6 +150,7 @@ Settings::Units unitsForIndex(NSInteger index)
NSString * str = [NSString stringWithFormat:@"Version: %@ \n", [[NSBundle mainBundle] infoDictionary][@"CFBundleVersion"]];
NSString * text = [NSString stringWithFormat:@"%@%@", str, [NSString stringWithUTF8String:s.c_str()]];
WebViewController * aboutViewController = [[WebViewController alloc] initWithHtml:text baseUrl:nil andTitleOrNil:NSLocalizedString(@"about", nil)];
aboutViewController.openInSafari = YES;
[self.navigationController pushViewController:aboutViewController animated:YES];
}
}