-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.m
86 lines (59 loc) · 2.42 KB
/
main.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#import <UIKit/UIKit.h>
@interface AppController : UIViewController
@end
@implementation AppController
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
return toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || toInterfaceOrientation == UIInterfaceOrientationLandscapeRight;
}
#ifdef __IPHONE_6_0
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscape;
}
#endif
@end
@interface HTML5AppDelegate : UIResponder <UIApplicationDelegate, UIWebViewDelegate>
@end
@implementation HTML5AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[[UIApplication sharedApplication] setStatusBarHidden:YES];
UIWindow *window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
UIWebView *webview = [[UIWebView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
webview.delegate = self;
//`html` folder in xcode should be blue
NSString *path = [[NSBundle mainBundle] pathForResource:@"html/index" ofType:@"html"];
NSString *html = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
NSURL *baseUrl = [NSURL fileURLWithPath:[path stringByDeletingLastPathComponent] isDirectory:YES];
[webview loadHTMLString:html baseURL:baseUrl];
//prevent zooming
webview.scalesPageToFit = NO;
//prevent bouncing
webview.scrollView.bounces = NO;
//set to landscape mode
CGAffineTransform rotation = CGAffineTransformMakeRotation(M_PI_2);
webview.transform = rotation;
webview.bounds = CGRectMake(0,0,1024,768);
UIViewController *controller = [[AppController alloc] init];
self.window.rootViewController = controller;
controller.view = webview;
[window makeKeyAndVisible];
return YES;
}
//if you want links to open in safari
- (BOOL)webView:(UIWebView *)view shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)type
{
if (type == UIWebViewNavigationTypeLinkClicked) {
[[UIApplication sharedApplication] openURL:[request URL]];
return NO;
}
return YES;
}
@end
int main(int argc, char *argv[])
{
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
}
}