Skip to content

Commit 71f8908

Browse files
committed
Update RWebViewController.
1 parent 8db7e93 commit 71f8908

File tree

7 files changed

+267
-3
lines changed

7 files changed

+267
-3
lines changed

WebAppWrapper.xcodeproj/project.pbxproj

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@
1818
FA68567E174CD862001C8F42 /* Default-568h@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = FA68567D174CD862001C8F42 /* Default-568h@2x.png */; };
1919
FA685687174CD870001C8F42 /* RootViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = FA685686174CD870001C8F42 /* RootViewController.m */; };
2020
FA68568B174CD8E6001C8F42 /* RWebViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = FA68568A174CD8E6001C8F42 /* RWebViewController.m */; };
21+
FA6856C1174D9916001C8F42 /* NavBack.png in Resources */ = {isa = PBXBuildFile; fileRef = FA6856BD174D9916001C8F42 /* NavBack.png */; };
22+
FA6856C2174D9916001C8F42 /* NavBack@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = FA6856BE174D9916001C8F42 /* NavBack@2x.png */; };
23+
FA6856C3174D9916001C8F42 /* NavForward.png in Resources */ = {isa = PBXBuildFile; fileRef = FA6856BF174D9916001C8F42 /* NavForward.png */; };
24+
FA6856C4174D9916001C8F42 /* NavForward@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = FA6856C0174D9916001C8F42 /* NavForward@2x.png */; };
25+
FAD9B338175F6F9400F2DAEB /* MobileCoreServices.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FAD9B337175F6F9400F2DAEB /* MobileCoreServices.framework */; };
2126
/* End PBXBuildFile section */
2227

2328
/* Begin PBXFileReference section */
@@ -38,13 +43,19 @@
3843
FA685686174CD870001C8F42 /* RootViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RootViewController.m; sourceTree = "<group>"; };
3944
FA685689174CD8E6001C8F42 /* RWebViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RWebViewController.h; sourceTree = "<group>"; };
4045
FA68568A174CD8E6001C8F42 /* RWebViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RWebViewController.m; sourceTree = "<group>"; };
46+
FA6856BD174D9916001C8F42 /* NavBack.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = NavBack.png; sourceTree = "<group>"; };
47+
FA6856BE174D9916001C8F42 /* NavBack@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "NavBack@2x.png"; sourceTree = "<group>"; };
48+
FA6856BF174D9916001C8F42 /* NavForward.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = NavForward.png; sourceTree = "<group>"; };
49+
FA6856C0174D9916001C8F42 /* NavForward@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "NavForward@2x.png"; sourceTree = "<group>"; };
50+
FAD9B337175F6F9400F2DAEB /* MobileCoreServices.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = MobileCoreServices.framework; path = System/Library/Frameworks/MobileCoreServices.framework; sourceTree = SDKROOT; };
4151
/* End PBXFileReference section */
4252

4353
/* Begin PBXFrameworksBuildPhase section */
4454
FA685661174CD862001C8F42 /* Frameworks */ = {
4555
isa = PBXFrameworksBuildPhase;
4656
buildActionMask = 2147483647;
4757
files = (
58+
FAD9B338175F6F9400F2DAEB /* MobileCoreServices.framework in Frameworks */,
4859
FA685668174CD862001C8F42 /* UIKit.framework in Frameworks */,
4960
FA68566A174CD862001C8F42 /* Foundation.framework in Frameworks */,
5061
FA68566C174CD862001C8F42 /* CoreGraphics.framework in Frameworks */,
@@ -74,6 +85,7 @@
7485
FA685666174CD862001C8F42 /* Frameworks */ = {
7586
isa = PBXGroup;
7687
children = (
88+
FAD9B337175F6F9400F2DAEB /* MobileCoreServices.framework */,
7789
FA685667174CD862001C8F42 /* UIKit.framework */,
7890
FA685669174CD862001C8F42 /* Foundation.framework */,
7991
FA68566B174CD862001C8F42 /* CoreGraphics.framework */,
@@ -84,6 +96,7 @@
8496
FA68566D174CD862001C8F42 /* WebAppWrapper */ = {
8597
isa = PBXGroup;
8698
children = (
99+
FA6856BB174D98E7001C8F42 /* Resources */,
87100
FA685688174CD8DE001C8F42 /* Utils */,
88101
FA685684174CD866001C8F42 /* View Controllers */,
89102
FA685676174CD862001C8F42 /* AppDelegate.h */,
@@ -125,6 +138,25 @@
125138
name = Utils;
126139
sourceTree = "<group>";
127140
};
141+
FA6856BB174D98E7001C8F42 /* Resources */ = {
142+
isa = PBXGroup;
143+
children = (
144+
FA6856BC174D98ED001C8F42 /* Images */,
145+
);
146+
name = Resources;
147+
sourceTree = "<group>";
148+
};
149+
FA6856BC174D98ED001C8F42 /* Images */ = {
150+
isa = PBXGroup;
151+
children = (
152+
FA6856BD174D9916001C8F42 /* NavBack.png */,
153+
FA6856BE174D9916001C8F42 /* NavBack@2x.png */,
154+
FA6856BF174D9916001C8F42 /* NavForward.png */,
155+
FA6856C0174D9916001C8F42 /* NavForward@2x.png */,
156+
);
157+
name = Images;
158+
sourceTree = "<group>";
159+
};
128160
/* End PBXGroup section */
129161

130162
/* Begin PBXNativeTarget section */
@@ -180,6 +212,10 @@
180212
FA68567A174CD862001C8F42 /* Default.png in Resources */,
181213
FA68567C174CD862001C8F42 /* Default@2x.png in Resources */,
182214
FA68567E174CD862001C8F42 /* Default-568h@2x.png in Resources */,
215+
FA6856C1174D9916001C8F42 /* NavBack.png in Resources */,
216+
FA6856C2174D9916001C8F42 /* NavBack@2x.png in Resources */,
217+
FA6856C3174D9916001C8F42 /* NavForward.png in Resources */,
218+
FA6856C4174D9916001C8F42 /* NavForward@2x.png in Resources */,
183219
);
184220
runOnlyForDeploymentPostprocessing = 0;
185221
};
@@ -308,6 +344,7 @@
308344
FA685683174CD862001C8F42 /* Release */,
309345
);
310346
defaultConfigurationIsVisible = 0;
347+
defaultConfigurationName = Release;
311348
};
312349
/* End XCConfigurationList section */
313350
};

WebAppWrapper/NavBack.png

429 Bytes
Loading

WebAppWrapper/NavBack@2x.png

706 Bytes
Loading

WebAppWrapper/NavForward.png

425 Bytes
Loading

WebAppWrapper/NavForward@2x.png

651 Bytes
Loading

WebAppWrapper/RWebViewController.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
#import <UIKit/UIKit.h>
1010

11-
@interface RWebViewController : UIViewController
11+
@interface RWebViewController : UIViewController <UIWebViewDelegate>
12+
13+
@property (nonatomic, strong) NSURL *startURL;
1214

1315
@end

WebAppWrapper/RWebViewController.m

Lines changed: 227 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,147 @@
66
// Copyright (c) 2013 Seymour Dev. All rights reserved.
77
//
88

9+
#import <MobileCoreServices/MobileCoreServices.h>
910
#import "RWebViewController.h"
1011

11-
@interface RWebViewController ()
12+
@interface RWebViewController () <UIActionSheetDelegate>
13+
14+
@property (nonatomic, strong) UIWebView *webView;
15+
16+
@property (nonatomic, strong) UIBarButtonItem *cancelButton;
17+
18+
@property (nonatomic, strong) UIBarButtonItem *backButton;
19+
@property (nonatomic, strong) UIBarButtonItem *forwardButton;
20+
@property (nonatomic, strong) UIBarButtonItem *refreshButton;
21+
@property (nonatomic, strong) UIBarButtonItem *stopButton;
22+
@property (nonatomic, strong) UIBarButtonItem *moreActionButton;
23+
24+
@property (nonatomic, weak) UIActionSheet *moreActionSheet;
25+
26+
- (void)dismiss;
27+
- (void)showMoreActionSheet;
28+
29+
- (void)loadStartPage;
30+
- (void)refresh;
31+
- (void)stopLoading;
32+
- (void)goBack;
33+
- (void)goForward;
34+
35+
- (void)setButtonWithLoadingStatus:(BOOL)loading;
36+
- (void)refreshNavigationButtonStatus;
37+
38+
- (void)cancelButtonPressed:(id)sender;
39+
- (void)backButtonPressed:(id)sender;
40+
- (void)forwardButtonPressed:(id)sender;
41+
- (void)refreshButtonPressed:(id)sender;
42+
- (void)stopButtonPressed:(id)sender;
43+
- (void)moreActionButtonPressed:(id)sender;
1244

1345
@end
1446

1547
@implementation RWebViewController
1648

49+
#pragma mark - View control
50+
51+
- (void)dismiss
52+
{
53+
[self dismissViewControllerAnimated:YES completion:nil];
54+
}
55+
56+
- (void)showMoreActionSheet
57+
{
58+
UIActionSheet *moreActionSheet = [[UIActionSheet alloc] initWithTitle:nil
59+
delegate:self
60+
cancelButtonTitle:NSLocalizedString(@"Cancel", nil)
61+
destructiveButtonTitle:nil
62+
otherButtonTitles:NSLocalizedString(@"Copy link", nil), NSLocalizedString(@"Open in Safari", nil), nil];
63+
self.moreActionSheet = moreActionSheet;
64+
[moreActionSheet showFromBarButtonItem:self.moreActionButton animated:YES];
65+
}
66+
67+
#pragma mark - Web view control
68+
69+
- (void)loadStartPage
70+
{
71+
NSURLRequest *request = [NSURLRequest requestWithURL:self.startURL];
72+
[self.webView loadRequest:request];
73+
}
74+
75+
- (void)refresh
76+
{
77+
[self.webView reload];
78+
}
79+
80+
- (void)stopLoading
81+
{
82+
[self.webView stopLoading];
83+
}
84+
85+
- (void)goBack
86+
{
87+
if (self.webView.canGoBack) {
88+
[self.webView goBack];
89+
}
90+
}
91+
92+
- (void)goForward
93+
{
94+
if (self.webView.canGoForward) {
95+
[self.webView goForward];
96+
}
97+
}
98+
99+
#pragma mark - Toolbar items control
100+
101+
- (void)setButtonWithLoadingStatus:(BOOL)loading
102+
{
103+
NSUInteger buttonIndex = ([self.toolbarItems indexOfObject:self.refreshButton] ^ NSNotFound |
104+
[self.toolbarItems indexOfObject:self.stopButton] ^ NSNotFound) ^ NSNotFound;
105+
NSMutableArray *toolbarItems = self.toolbarItems.mutableCopy;
106+
[toolbarItems replaceObjectAtIndex:buttonIndex withObject:(loading ? self.stopButton : self.refreshButton)];
107+
[self setToolbarItems:toolbarItems animated:NO];
108+
}
109+
110+
- (void)refreshNavigationButtonStatus
111+
{
112+
self.backButton.enabled = self.webView.canGoBack;
113+
self.forwardButton.enabled = self.webView.canGoForward;
114+
}
115+
116+
#pragma mark - Actions
117+
118+
- (void)cancelButtonPressed:(id)sender
119+
{
120+
[self dismiss];
121+
}
122+
123+
- (void)backButtonPressed:(id)sender
124+
{
125+
[self goBack];
126+
}
127+
128+
- (void)forwardButtonPressed:(id)sender
129+
{
130+
[self goForward];
131+
}
132+
133+
- (void)refreshButtonPressed:(id)sender
134+
{
135+
[self refresh];
136+
}
137+
138+
- (void)stopButtonPressed:(id)sender
139+
{
140+
[self stopLoading];
141+
}
142+
143+
- (void)moreActionButtonPressed:(id)sender
144+
{
145+
[self showMoreActionSheet];
146+
}
147+
148+
#pragma mark - Life cycle
149+
17150
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
18151
{
19152
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
@@ -26,7 +159,55 @@ - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
26159
- (void)viewDidLoad
27160
{
28161
[super viewDidLoad];
29-
// Do any additional setup after loading the view.
162+
163+
// Init navigation items.
164+
165+
self.cancelButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(cancelButtonPressed:)];
166+
167+
// Add navigation items.
168+
169+
self.navigationItem.leftBarButtonItem = self.cancelButton;
170+
171+
// Init toolbar items.
172+
173+
self.backButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"NavBack"] style:UIBarButtonItemStylePlain target:self action:@selector(backButtonPressed:)];
174+
self.forwardButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"NavForward"] style:UIBarButtonItemStylePlain target:self action:@selector(forwardButtonPressed:)];
175+
self.refreshButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:@selector(refreshButtonPressed:)];
176+
self.stopButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemStop target:self action:@selector(stopButtonPressed:)];
177+
self.moreActionButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:@selector(moreActionButtonPressed:)];
178+
179+
// Add toolbar & toolbar items.
180+
181+
self.navigationController.toolbarHidden = NO;
182+
UIBarButtonItem *fixedSpaceItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
183+
fixedSpaceItem.width = 12.0f;
184+
UIBarButtonItem *flexibleSpaceItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
185+
self.toolbarItems = @[
186+
fixedSpaceItem,
187+
self.backButton,
188+
flexibleSpaceItem,
189+
self.forwardButton,
190+
flexibleSpaceItem,
191+
self.refreshButton,
192+
flexibleSpaceItem,
193+
self.moreActionButton,
194+
fixedSpaceItem
195+
];
196+
[self refreshNavigationButtonStatus];
197+
198+
// Init & add web view.
199+
200+
self.webView = [[UIWebView alloc] initWithFrame:self.view.bounds];
201+
self.webView.delegate = self;
202+
self.webView.scalesPageToFit = YES;
203+
[self.view addSubview:self.webView];
204+
}
205+
206+
- (void)viewDidAppear:(BOOL)animated
207+
{
208+
[super viewDidAppear:animated];
209+
210+
[self loadStartPage];
30211
}
31212

32213
- (void)didReceiveMemoryWarning
@@ -35,4 +216,48 @@ - (void)didReceiveMemoryWarning
35216
// Dispose of any resources that can be recreated.
36217
}
37218

219+
#pragma mark - Web view delegate
220+
221+
- (void)webViewDidStartLoad:(UIWebView *)webView
222+
{
223+
if (webView == self.webView) {
224+
[self setButtonWithLoadingStatus:YES];
225+
[self refreshNavigationButtonStatus];
226+
}
227+
}
228+
229+
- (void)webViewDidFinishLoad:(UIWebView *)webView
230+
{
231+
if (webView == self.webView) {
232+
[self setButtonWithLoadingStatus:NO];
233+
[self refreshNavigationButtonStatus];
234+
}
235+
}
236+
237+
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
238+
{
239+
if (webView == self.webView) {
240+
[self setButtonWithLoadingStatus:NO];
241+
[self refreshNavigationButtonStatus];
242+
}
243+
}
244+
245+
#pragma mark - Action sheet delegate
246+
247+
- (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex
248+
{
249+
if (actionSheet == self.moreActionSheet) {
250+
switch (buttonIndex) {
251+
case 0: // Copy link
252+
[[UIPasteboard generalPasteboard] setValue:self.webView.request.URL forPasteboardType:(NSString *)kUTTypeURL];
253+
break;
254+
case 1: // Open in Safari
255+
[[UIApplication sharedApplication] openURL:self.webView.request.URL];
256+
break;
257+
default:
258+
break;
259+
}
260+
}
261+
}
262+
38263
@end

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy