diff --git a/Browser/ViewController.m b/Browser/ViewController.m index 8bb6764..85567a3 100644 --- a/Browser/ViewController.m +++ b/Browser/ViewController.m @@ -23,7 +23,7 @@ @interface ViewController () NSString *temporaryURL; } -@property UIWebView *webview; +@property id webview; @property (strong) CADisplayLink *link; @property (strong, nonatomic) GCController *controller; @property BOOL cursorMode; @@ -39,17 +39,20 @@ - (void)viewDidLoad { cursorView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"Cursor"]]; cursorView.hidden = YES; - self.webview = [[UIWebView alloc] initWithFrame:[UIScreen mainScreen].bounds]; - [self.webview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.apple.com"]]]; + + Class UIWebViewClass = NSClassFromString(@"UIWebView"); + + _webview = [[UIWebViewClass alloc] initWithFrame:[UIScreen mainScreen].bounds]; + [_webview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.apple.com"]]]; - [self.view addSubview:self.webview]; + [self.view addSubview:_webview]; [self.view addSubview:cursorView]; self.link = [CADisplayLink displayLinkWithTarget:self selector:@selector(updateCursor)]; [self.link addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSRunLoopCommonModes]; - self.webview.scrollView.bounces = YES; - self.webview.scrollView.panGestureRecognizer.allowedTouchTypes = @[ @(UITouchTypeIndirect) ]; + [_webview scrollView].bounces = YES; + [_webview scrollView].panGestureRecognizer.allowedTouchTypes = @[ @(UITouchTypeIndirect) ]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(setupController) name:GCControllerDidConnectNotification object:nil]; } @@ -60,14 +63,14 @@ -(void)toggleMode if (self.cursorMode) { - self.webview.scrollView.scrollEnabled = NO; - self.webview.userInteractionEnabled = NO; + [_webview scrollView].scrollEnabled = NO; + [_webview setUserInteractionEnabled:NO]; cursorView.hidden = NO; } else { - self.webview.scrollView.scrollEnabled = YES; - self.webview.userInteractionEnabled = YES; + [_webview scrollView].scrollEnabled = YES; + [_webview setUserInteractionEnabled:YES]; cursorView.hidden = YES; } } @@ -92,13 +95,13 @@ -(void)pressesEnded:(NSSet *)presses withEvent:(UIPressesEvent *)even [self dismissViewControllerAnimated:YES completion:nil]; } else - [self.webview goBack]; + [_webview goBack]; } else if (presses.anyObject.type == UIPressTypeSelect) { /* Gross. */ CGPoint point = [self.webview convertPoint:cursorView.frame.origin toView:nil]; - [self.webview stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"document.elementFromPoint(%i, %i).click()", (int)point.x, (int)point.y]]; + [_webview stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"document.elementFromPoint(%i, %i).click()", (int)point.x, (int)point.y]]; } else if (presses.anyObject.type == UIPressTypePlayPause) @@ -123,7 +126,7 @@ -(void)pressesEnded:(NSSet *)presses withEvent:(UIPressesEvent *)even style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { - [self.webview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://%@", temporaryURL]]]]; + [_webview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://%@", temporaryURL]]]]; temporaryURL = nil; }];