Open external links in a modal UIWebView #325

Merged
merged 5 commits into from Mar 5, 2012
@@ -13,6 +13,10 @@
1DF5F4E00D08C38300B7A737 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1DF5F4DF0D08C38300B7A737 /* UIKit.framework */; };
288765FD0DF74451002DB57D /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 288765FC0DF74451002DB57D /* CoreGraphics.framework */; };
578A4F2114B1AF570054CD50 /* MessageUI.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 578A4F2014B1AF570054CD50 /* MessageUI.framework */; };
+ 84E7F05614F63CC8005B1929 /* ModalViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 84E7F05514F63CC8005B1929 /* ModalViewController.xib */; };
+ 84E7F05A14F63CDF005B1929 /* ModalViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 84E7F05914F63CDF005B1929 /* ModalViewController.m */; };
+ 84ED947314FC389000538EE5 /* forward.png in Resources */ = {isa = PBXBuildFile; fileRef = 84ED947214FC389000538EE5 /* forward.png */; };
+ 84ED947614FC389D00538EE5 /* back.png in Resources */ = {isa = PBXBuildFile; fileRef = 84ED947514FC389D00538EE5 /* back.png */; };
9F123763129F133700B7E8C8 /* Downloader.m in Sources */ = {isa = PBXBuildFile; fileRef = 9F123762129F133700B7E8C8 /* Downloader.m */; };
9F242EDA11FB344D00641757 /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9F242ED911FB344D00641757 /* QuartzCore.framework */; };
9F4F07F411F8DE8200375A8C /* RootViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 9F4F07F211F8DE8200375A8C /* RootViewController.m */; };
@@ -71,6 +75,11 @@
29B97316FDCFA39411CA2CEA /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
32CA4F630368D1EE00C91783 /* Baker_Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Baker_Prefix.pch; sourceTree = "<group>"; };
578A4F2014B1AF570054CD50 /* MessageUI.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = MessageUI.framework; path = System/Library/Frameworks/MessageUI.framework; sourceTree = SDKROOT; };
+ 84E7F05514F63CC8005B1929 /* ModalViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = ModalViewController.xib; sourceTree = "<group>"; };
+ 84E7F05814F63CDF005B1929 /* ModalViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ModalViewController.h; sourceTree = "<group>"; };
+ 84E7F05914F63CDF005B1929 /* ModalViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ModalViewController.m; sourceTree = "<group>"; };
+ 84ED947214FC389000538EE5 /* forward.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = forward.png; sourceTree = "<group>"; };
+ 84ED947514FC389D00538EE5 /* back.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = back.png; sourceTree = "<group>"; };
8D1107310486CEB800E47090 /* Baker-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "Baker-Info.plist"; plistStructureDefinitionIdentifier = "com.apple.xcode.plist.structure-definition.iphone.info-plist"; sourceTree = "<group>"; };
9F123761129F133700B7E8C8 /* Downloader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Downloader.h; sourceTree = "<group>"; };
9F123762129F133700B7E8C8 /* Downloader.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Downloader.m; sourceTree = "<group>"; };
@@ -165,6 +174,8 @@
F4EC203712862D4D008E94D1 /* InterceptorWindow.m */,
9F123761129F133700B7E8C8 /* Downloader.h */,
9F123762129F133700B7E8C8 /* Downloader.m */,
+ 84E7F05814F63CDF005B1929 /* ModalViewController.h */,
+ 84E7F05914F63CDF005B1929 /* ModalViewController.m */,
);
path = Classes;
sourceTree = "<group>";
@@ -205,6 +216,9 @@
29B97317FDCFA39411CA2CEA /* Resources */ = {
isa = PBXGroup;
children = (
+ 84ED947514FC389D00538EE5 /* back.png */,
+ 84ED947214FC389000538EE5 /* forward.png */,
+ 84E7F05514F63CC8005B1929 /* ModalViewController.xib */,
BFEC41E51309D9CA00628DF3 /* ios-icon-iphone57.png */,
BFEC41E71309D9CE00628DF3 /* ios-icon-iphone114.png */,
BFBACF321274CD38009D9595 /* ios-icon-ipad72.png */,
@@ -376,6 +390,9 @@
BFBACF331274CD38009D9595 /* ios-icon-ipad72.png in Resources */,
BFEC41E61309D9CA00628DF3 /* ios-icon-iphone57.png in Resources */,
BFEC41E81309D9CE00628DF3 /* ios-icon-iphone114.png in Resources */,
+ 84E7F05614F63CC8005B1929 /* ModalViewController.xib in Resources */,
+ 84ED947314FC389000538EE5 /* forward.png in Resources */,
+ 84ED947614FC389D00538EE5 /* back.png in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -425,6 +442,7 @@
D2263F38144B2F2900DCBECF /* zip.c in Sources */,
D2263F39144B2F2900DCBECF /* SSZipArchive.m in Sources */,
F4968A871498C29F00D6689C /* JSONKit.m in Sources */,
+ 84E7F05A14F63CDF005B1929 /* ModalViewController.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -0,0 +1,56 @@
+//
+// ModalViewController.h
+// Baker
+//
+// ==========================================================================================
+//
+// Copyright (c) 2010-2011, Davide Casali, Marco Colombo, Alessandro Morandi
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without modification, are
+// permitted provided that the following conditions are met:
+//
+// Redistributions of source code must retain the above copyright notice, this list of
+// conditions and the following disclaimer.
+// Redistributions in binary form must reproduce the above copyright notice, this list of
+// conditions and the following disclaimer in the documentation and/or other materials
+// provided with the distribution.
+// Neither the name of the Baker Framework nor the names of its contributors may be used to
+// endorse or promote products derived from this software without specific prior written
+// permission.
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
+// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
+// SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+//
+
+#import <UIKit/UIKit.h>
+@protocol modalWebViewDelegate;
+
+@interface ModalViewController : UIViewController <UIWebViewDelegate> {
+ id <modalWebViewDelegate> delegate;
+ NSURL *myUrl;
+}
+
+@property (nonatomic, assign) id <modalWebViewDelegate> delegate;
+@property (nonatomic, assign) IBOutlet UIWebView *webView;
+@property (nonatomic, assign) IBOutlet UIBarButtonItem *backButton;
+@property (nonatomic, assign) IBOutlet UIBarButtonItem *forwardButton;
+
+- (id)initWithUrl:(NSURL *)url;
+- (IBAction)dismissAction:(id)sender;
+- (IBAction)goBack:(id)sender;
+- (IBAction)goForward:(id)sender;
+- (IBAction)openInSafari:(id)sender;
+
+@end
+
+@protocol modalWebViewDelegate <NSObject>
+- (void) done:(ModalViewController *)controller;
+- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation;
+@end
@@ -0,0 +1,94 @@
+//
+// ModalViewController.m
+// Baker
+//
+// ==========================================================================================
+//
+// Copyright (c) 2010-2012, Davide Casali, Marco Colombo, Alessandro Morandi
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without modification, are
+// permitted provided that the following conditions are met:
+//
+// Redistributions of source code must retain the above copyright notice, this list of
+// conditions and the following disclaimer.
+// Redistributions in binary form must reproduce the above copyright notice, this list of
+// conditions and the following disclaimer in the documentation and/or other materials
+// provided with the distribution.
+// Neither the name of the Baker Framework nor the names of its contributors may be used to
+// endorse or promote products derived from this software without specific prior written
+// permission.
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
+// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
+// SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+//
+
+#import "ModalViewController.h"
+
+@implementation ModalViewController
+@synthesize delegate, webView, backButton, forwardButton;
+
+- (id)initWithUrl:(NSURL *)url {
+ myUrl = url;
+
+ return [self initWithNibName:NSStringFromClass([ModalViewController class]) bundle:nil];
+}
+
+- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
+ if (!(self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]))
+ return nil;
+
+ return self;
+}
+
+#pragma mark - Orientation
+
+- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)orientation {
+ return [[self delegate] shouldAutorotateToInterfaceOrientation:orientation];
+}
+
+#pragma mark - View lifecycle
+
+- (void)dealloc {
+ [super dealloc];
+}
+
+- (void)viewDidLoad {
+ self.view.backgroundColor = [UIColor whiteColor];
+ [webView loadRequest:[NSURLRequest requestWithURL:myUrl]];
+}
+
+- (void)viewDidUnload {
+}
+
+#pragma mark - UIWebView delegate methods
+- (void)webViewDidFinishLoad:(UIWebView *)webView1 {
+ backButton.enabled = [webView1 canGoBack];
+ forwardButton.enabled = [webView1 canGoForward];
+}
+
+#pragma mark - Interface Builder Actions
+
+- (IBAction)dismissAction:(id)sender {
+ [[self delegate] done:self];
+}
+
+- (IBAction)goBack:(id)sender {
+ [webView goBack];
+}
+
+- (IBAction)goForward:(id)sender {
+ [webView goForward];
+}
+
+- (IBAction)openInSafari:(id)sender {
+ [[UIApplication sharedApplication] openURL:webView.request.URL];
+}
+
+@end
@@ -33,12 +33,13 @@
#import <UIKit/UIKit.h>
#import <MessageUI/MessageUI.h>
#import "IndexViewController.h"
+#import "ModalViewController.h"
#import "Properties.h"
@class Downloader;
-@interface RootViewController : UIViewController <UIWebViewDelegate, UIScrollViewDelegate, MFMailComposeViewControllerDelegate> {
+@interface RootViewController : UIViewController <UIWebViewDelegate, UIScrollViewDelegate, MFMailComposeViewControllerDelegate, modalWebViewDelegate> {
CGRect screenBounds;
@@ -72,6 +73,8 @@
UIWebView *currPage;
UIWebView *nextPage;
+ UIColor *webViewBackground;
+
CGRect upTapArea;
CGRect downTapArea;
CGRect leftTapArea;
@@ -90,6 +93,7 @@
UIAlertView *feedbackAlert;
IndexViewController *indexViewController;
+ ModalViewController *myModalViewController;
Properties *properties;
}
@@ -122,6 +126,10 @@
- (void)loadSlot:(int)slot withPage:(int)page;
- (BOOL)loadWebView:(UIWebView *)webview withPage:(int)page;
+#pragma mark - MODAL WEBVIEW
+- (void)loadModalWebView:(NSURL *) url;
+- (void)done:(ModalViewController *)controller;
+
#pragma mark - SCROLLVIEW
- (CGRect)frameForPage:(int)page;
- (void)resetScrollView;
Oops, something went wrong.