2 // MessageViewController.m
5 // Created by Christian Brunschen on 30/07/2008.
7 * Copyright 2008 ZXing authors
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
22 #import "MessageViewController.h"
25 @implementation MessageViewController
27 @synthesize callbackTarget;
28 @synthesize callbackSelectorSuccess;
29 @synthesize callbackSelectorFailure;
30 @synthesize contentURL;
32 - (UIWebView *)webView {
33 return (UIWebView *)self.view;
36 - (id)initWithMessageFilename:(NSString *)filename
40 if (self = [super initWithNibName:@"Message" bundle:nil]) {
41 self.callbackTarget = cbt;
42 self.callbackSelectorSuccess = ss;
43 self.callbackSelectorFailure = fs;
44 self.contentURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:filename
52 self.webView.delegate = self;
53 [self.webView loadRequest:[NSURLRequest requestWithURL:self.contentURL]];
61 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
62 // Return YES for supported orientations
63 return (interfaceOrientation == UIInterfaceOrientationPortrait);
66 - (void)didReceiveMemoryWarning {
67 [super didReceiveMemoryWarning]; // Releases the view if it doesn't have a superview
68 // Release anything that's not essential, such as cached data
76 // open a URL, asynchronously
77 - (void) openURL:(NSURL *)url {
79 [[UIApplication sharedApplication] openURL:url];
83 // UIWebViewDelegate methods
85 - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
86 if ([[request URL] isFileURL]) {
87 // only load 'file' URL requests ourselves
90 // any other url:s are handed off to the system
91 NSURL *url = [[request URL] retain];
92 [self performSelectorOnMainThread:@selector(openURL:) withObject:url waitUntilDone:false];
97 - (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error {
98 NSLog(@"failed to load content, performing failure callback");
99 [self.callbackTarget performSelector:self.callbackSelectorFailure withObject:self afterDelay:0.0];
102 - (void)webViewDidFinishLoad:(UIWebView *)webView {
103 NSLog(@"finished loading content, performing success callback");
104 [self.callbackTarget performSelector:self.callbackSelectorSuccess withObject:self afterDelay:0.0];