Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions CachedWebView.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@
FB237EBE14D5B86100F30AD8 = {
isa = PBXGroup;
children = (
FB39D08214D5BB1F002A6D1A /* README.md */,
C800AAE6166E77B20027E1E5 /* NSString+Sha1.h */,
C800AAE7166E77B20027E1E5 /* NSString+Sha1.m */,
FB39D08214D5BB1F002A6D1A /* README.md */,
FB237EEA14D5B87400F30AD8 /* RNCachingURLProtocol.h */,
FB237EEB14D5B87400F30AD8 /* RNCachingURLProtocol.m */,
FB237EEC14D5B89700F30AD8 /* Reachability.m */,
Expand Down Expand Up @@ -218,7 +218,7 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
ARCHS = "$(ARCHS_STANDARD_32_BIT)";
ARCHS = "$(ARCHS_STANDARD)";
CLANG_ENABLE_OBJC_ARC = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
COPY_PHASE_STRIP = NO;
Expand All @@ -244,7 +244,7 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
ARCHS = "$(ARCHS_STANDARD_32_BIT)";
ARCHS = "$(ARCHS_STANDARD)";
CLANG_ENABLE_OBJC_ARC = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
COPY_PHASE_STRIP = YES;
Expand All @@ -268,6 +268,7 @@
GCC_PREFIX_HEADER = "CachedWebView/CachedWebView-Prefix.pch";
INFOPLIST_FILE = "CachedWebView/CachedWebView-Info.plist";
PRODUCT_NAME = "$(TARGET_NAME)";
TARGETED_DEVICE_FAMILY = "1,2";
WRAPPER_EXTENSION = app;
};
name = Debug;
Expand All @@ -279,6 +280,7 @@
GCC_PREFIX_HEADER = "CachedWebView/CachedWebView-Prefix.pch";
INFOPLIST_FILE = "CachedWebView/CachedWebView-Info.plist";
PRODUCT_NAME = "$(TARGET_NAME)";
TARGETED_DEVICE_FAMILY = "1,2";
WRAPPER_EXTENSION = app;
};
name = Release;
Expand Down
2 changes: 1 addition & 1 deletion CachedWebView/AppDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@

@property (strong, nonatomic) UIWindow *window;

@property (strong, nonatomic) ViewController *viewController;
@property (strong, nonatomic) UITabBarController *viewController;

@end
43 changes: 33 additions & 10 deletions CachedWebView/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,41 @@

@implementation AppDelegate

@synthesize window = _window;
@synthesize viewController = _viewController;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[NSURLProtocol registerClass:[RNCachingURLProtocol class]];

self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
//only cache Steam
[RNCachingURLProtocol setShouldHandleRequest:^BOOL(NSURLRequest * _Nonnull aRequest) {
if(!aRequest.URL.host) {
return NO;
}

BOOL br = [aRequest.URL.host rangeOfString:@"steamcommunity.com"].location != NSNotFound;
if(br) {
NSLog(@"cache %@", aRequest.URL.host);
}
return br;
}];

//set our protocol
[NSURLProtocol registerClass:[RNCachingURLProtocol class]];

//prepare the content vcs
ViewController *viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
viewController.url = [NSURL URLWithString:@"http://steamcommunity.com"];
viewController.title = @"cached Steamcommunity";
ViewController *viewController2 = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
viewController2.url = [NSURL URLWithString:@"http://www.spiegel.de"];
viewController2.title = @"uncached Spiegel";

//add tabbar
self.viewController = [[UITabBarController alloc] init];
self.viewController.viewControllers = @[viewController, viewController2];

//add the window
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
}

@end
75 changes: 40 additions & 35 deletions CachedWebView/CachedWebView-Info.plist
Original file line number Diff line number Diff line change
@@ -1,39 +1,44 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleDisplayName</key>
<string>${PRODUCT_NAME}</string>
<key>CFBundleExecutable</key>
<string>${EXECUTABLE_NAME}</string>
<key>CFBundleIdentifier</key>
<string>net.robnapier.${PRODUCT_NAME:rfc1034identifier}</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>${PRODUCT_NAME}</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1.0</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>armv7</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
</dict>
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleDisplayName</key>
<string>${PRODUCT_NAME}</string>
<key>CFBundleExecutable</key>
<string>${EXECUTABLE_NAME}</string>
<key>CFBundleIdentifier</key>
<string>net.robnapier.${PRODUCT_NAME:rfc1034identifier}</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>${PRODUCT_NAME}</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1.0</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>armv7</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
</dict>
</plist>
3 changes: 1 addition & 2 deletions CachedWebView/ViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,5 @@
#import <UIKit/UIKit.h>

@interface ViewController : UIViewController
@property (strong, nonatomic) IBOutlet UIWebView *webView;

@property (strong, nonatomic) NSURL *url;
@end
18 changes: 14 additions & 4 deletions CachedWebView/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,26 @@
#import "ViewController.h"

@interface ViewController ()

@property (strong, nonatomic) IBOutlet UIWebView *webView;
@end

@implementation ViewController
@synthesize webView = webView_;

- (void)viewDidLoad
{
[super viewDidLoad];
[self.webView loadRequest:[[NSURLRequest alloc] initWithURL:[NSURL URLWithString:@"http://cnn.com"]]];
[super viewDidLoad];

id url = self.url;
if(url) {
[self.webView loadRequest:[[NSURLRequest alloc] initWithURL:url]];
}
}

- (void)setUrl:(NSURL *)url {
_url = url;

if(self.isViewLoaded) {
[self.webView loadRequest:[[NSURLRequest alloc] initWithURL:url]];
}
}
@end
Loading