Permalink
Browse files

Open external websites in a modal UIWebView instead of Safari

  • Loading branch information...
Sebastian Steinmetz
Sebastian Steinmetz committed Feb 23, 2012
1 parent 2201076 commit 5e1a643363ccbed074e73da08cbbe5a1001bd63f
@@ -13,6 +13,8 @@
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 */; };
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 +73,9 @@
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>"; };
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 +170,8 @@
F4EC203712862D4D008E94D1 /* InterceptorWindow.m */,
9F123761129F133700B7E8C8 /* Downloader.h */,
9F123762129F133700B7E8C8 /* Downloader.m */,
+ 84E7F05814F63CDF005B1929 /* ModalViewController.h */,
+ 84E7F05914F63CDF005B1929 /* ModalViewController.m */,
);
path = Classes;
sourceTree = "<group>";
@@ -205,6 +212,7 @@
29B97317FDCFA39411CA2CEA /* Resources */ = {
isa = PBXGroup;
children = (
+ 84E7F05514F63CC8005B1929 /* ModalViewController.xib */,
BFEC41E51309D9CA00628DF3 /* ios-icon-iphone57.png */,
BFEC41E71309D9CE00628DF3 /* ios-icon-iphone114.png */,
BFBACF321274CD38009D9595 /* ios-icon-ipad72.png */,
@@ -376,6 +384,7 @@
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 */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -425,6 +434,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,66 @@
+/*
+ File: ModalViewController.h
+ Abstract: The view controller presented modally.
+ Version: 1.9
+
+ Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple
+ Inc. ("Apple") in consideration of your agreement to the following
+ terms, and your use, installation, modification or redistribution of
+ this Apple software constitutes acceptance of these terms. If you do
+ not agree with these terms, please do not use, install, modify or
+ redistribute this Apple software.
+
+ In consideration of your agreement to abide by the following terms, and
+ subject to these terms, Apple grants you a personal, non-exclusive
+ license, under Apple's copyrights in this original Apple software (the
+ "Apple Software"), to use, reproduce, modify and redistribute the Apple
+ Software, with or without modifications, in source and/or binary forms;
+ provided that if you redistribute the Apple Software in its entirety and
+ without modifications, you must retain this notice and the following
+ text and disclaimers in all such redistributions of the Apple Software.
+ Neither the name, trademarks, service marks or logos of Apple Inc. may
+ be used to endorse or promote products derived from the Apple Software
+ without specific prior written permission from Apple. Except as
+ expressly stated in this notice, no other rights or licenses, express or
+ implied, are granted by Apple herein, including but not limited to any
+ patent rights that may be infringed by your derivative works or by other
+ works in which the Apple Software may be incorporated.
+
+ The Apple Software is provided by Apple on an "AS IS" basis. APPLE
+ MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION
+ THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS
+ FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND
+ OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS.
+
+ IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL
+ OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION,
+ MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED
+ AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE),
+ STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE.
+
+ Copyright (C) 2010 Apple Inc. All Rights Reserved.
+
+ */
+
+#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;
+
+- (id)initWithUrl:(NSURL *)url;
+- (IBAction)dismissAction:(id)sender;
+
+@end
+
+@protocol modalWebViewDelegate <NSObject>
+- (void) done:(ModalViewController *)controller;
+@end
@@ -0,0 +1,86 @@
+/*
+ File: ModalViewController.m
+ Abstract: The view controller presented modally.
+ Version: 1.9
+
+ Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple
+ Inc. ("Apple") in consideration of your agreement to the following
+ terms, and your use, installation, modification or redistribution of
+ this Apple software constitutes acceptance of these terms. If you do
+ not agree with these terms, please do not use, install, modify or
+ redistribute this Apple software.
+
+ In consideration of your agreement to abide by the following terms, and
+ subject to these terms, Apple grants you a personal, non-exclusive
+ license, under Apple's copyrights in this original Apple software (the
+ "Apple Software"), to use, reproduce, modify and redistribute the Apple
+ Software, with or without modifications, in source and/or binary forms;
+ provided that if you redistribute the Apple Software in its entirety and
+ without modifications, you must retain this notice and the following
+ text and disclaimers in all such redistributions of the Apple Software.
+ Neither the name, trademarks, service marks or logos of Apple Inc. may
+ be used to endorse or promote products derived from the Apple Software
+ without specific prior written permission from Apple. Except as
+ expressly stated in this notice, no other rights or licenses, express or
+ implied, are granted by Apple herein, including but not limited to any
+ patent rights that may be infringed by your derivative works or by other
+ works in which the Apple Software may be incorporated.
+
+ The Apple Software is provided by Apple on an "AS IS" basis. APPLE
+ MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION
+ THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS
+ FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND
+ OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS.
+
+ IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL
+ OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION,
+ MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED
+ AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE),
+ STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE.
+
+ Copyright (C) 2010 Apple Inc. All Rights Reserved.
+
+ */
+
+#import "ModalViewController.h"
+
+@implementation ModalViewController
+@synthesize delegate, webView;
+
+- (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;
+
+ self.title = NSLocalizedString(@"ModalTitle", @"");
+
+ return self;
+}
+
+#pragma mark - View lifecycle
+
+- (void)dealloc {
+ [super dealloc];
+}
+
+- (void)viewDidLoad {
+ self.view.backgroundColor = [UIColor whiteColor];
+ [webView loadRequest:[NSURLRequest requestWithURL:myUrl]];
+}
+
+- (void)viewDidUnload {
+}
+
+- (IBAction)dismissAction:(id)sender {
+ [[self delegate] done:self];
+}
+
+@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;
@@ -90,6 +91,7 @@
UIAlertView *feedbackAlert;
IndexViewController *indexViewController;
+ ModalViewController *myModalViewController;
Properties *properties;
}
@@ -122,6 +124,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;
@@ -866,6 +866,24 @@ - (BOOL)loadWebView:(UIWebView*)webView withPage:(int)page {
return NO;
}
+#pragma mark - MODAL VIEW
+
+- (void)loadModalWebView:(NSURL *) url {
+ NSLog(@"» should load a modal view...");
+
+//myModalViewController = [[[ModalViewController alloc] initWithNibName:NSStringFromClass([ModalViewController class]) bundle:nil] autorelease];
+ myModalViewController = [[[ModalViewController alloc] initWithUrl:url] autorelease];
+ myModalViewController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
+ myModalViewController.delegate = self;
+
+
+ [self presentViewController:myModalViewController animated:YES completion:nil];
+}
+
+- (void) done:(ModalViewController *)controller {
+ [self dismissViewControllerAnimated:YES completion:nil];
+}
+
#pragma mark - SCROLLVIEW
- (CGRect)frameForPage:(int)page {
return CGRectMake(pageWidth * (page - 1), 0, pageWidth, pageHeight);
@@ -1093,11 +1111,11 @@ - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)
// We are regexp-ing three things: the string alone, the string first with other content, the string with other content in any other position
NSRegularExpression *replacerRegexp = [NSRegularExpression regularExpressionWithPattern:[[NSString alloc] initWithFormat:@"\\?%@$|(?<=\\?)%@&?|()&?%@", URL_OPEN_EXTERNAL, URL_OPEN_EXTERNAL, URL_OPEN_EXTERNAL] options:NSRegularExpressionCaseInsensitive error:NULL];
NSString *oldURL = [url absoluteString];
- NSLog(@" kjasdkajdals: %@", [replacerRegexp pattern]);
+ NSLog(@" replacement pattern: %@", [replacerRegexp pattern]);
NSString *newURL = [replacerRegexp stringByReplacingMatchesInString:oldURL options:0 range:NSMakeRange(0, [oldURL length]) withTemplate:@""];
NSLog(@" Opening with updated URL: %@", newURL);
- [[UIApplication sharedApplication] openURL:[NSURL URLWithString:newURL]];
+ [self loadModalWebView:url];
return NO;
}
}
@@ -1663,6 +1681,7 @@ - (void)dealloc {
[pages release];
[indexViewController release];
+ [myModalViewController release];
[scrollView release];
[currPage release];
[nextPage release];
Oops, something went wrong.

0 comments on commit 5e1a643

Please sign in to comment.