From 20a14ff16035d160ba8e52bb3ec13a04c4ee2604 Mon Sep 17 00:00:00 2001 From: FrankWu100 Date: Wed, 27 Nov 2013 00:51:10 +0800 Subject: [PATCH 1/6] Fix zh-Hant More appropriate use of Traditional Chinese habit --- .../zh-Hant.lproj/SVWebViewController.strings | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/SVWebViewController/zh-Hant.lproj/SVWebViewController.strings b/SVWebViewController/zh-Hant.lproj/SVWebViewController.strings index af4f4a4..111e1dd 100644 --- a/SVWebViewController/zh-Hant.lproj/SVWebViewController.strings +++ b/SVWebViewController/zh-Hant.lproj/SVWebViewController.strings @@ -1,3 +1,3 @@ -// Copyright (c) 2013 James Stout -"Open in Safari" = "打開Safari"; -"Open in Chrome" = "打開Chrome"; \ No newline at end of file +// Copyright (c) 2013 Frank Wu +"Open in Safari" = "在 Safari 開啓"; +"Open in Chrome" = "在 Chrome 開啓"; \ No newline at end of file From b63c8e0881a829b4f00c6efb6e62faab46e90d34 Mon Sep 17 00:00:00 2001 From: FrankWu100 Date: Fri, 29 Nov 2013 02:16:48 +0800 Subject: [PATCH 2/6] Added initWithHTMLString to load HTML's string Can be reload and go back from next web, because save a temp html file in to tmp dir. --- SVWebViewController/SVWebViewController.h | 1 + SVWebViewController/SVWebViewController.m | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/SVWebViewController/SVWebViewController.h b/SVWebViewController/SVWebViewController.h index 42e9dfe..9310a0b 100644 --- a/SVWebViewController/SVWebViewController.h +++ b/SVWebViewController/SVWebViewController.h @@ -12,5 +12,6 @@ - (id)initWithAddress:(NSString*)urlString; - (id)initWithURL:(NSURL*)URL; +- (id)initWithHTMLString:(NSString*)HTMLString; @end diff --git a/SVWebViewController/SVWebViewController.m b/SVWebViewController/SVWebViewController.m index 2e08ebc..ef48e8b 100644 --- a/SVWebViewController/SVWebViewController.m +++ b/SVWebViewController/SVWebViewController.m @@ -23,6 +23,7 @@ @interface SVWebViewController () - (id)initWithAddress:(NSString*)urlString; - (id)initWithURL:(NSURL*)URL; +- (id)initWithHTMLString:(NSString*)HTMLString; - (void)loadURL:(NSURL*)URL; - (void)updateToolbarItems; @@ -59,6 +60,19 @@ - (id)initWithURL:(NSURL*)pageURL { return self; } +- (id)initWithHTMLString:(NSString*)pageHTMLString { + + if(self = [super init]) { + NSURL *tmpDirURL = [NSURL fileURLWithPath:NSTemporaryDirectory() isDirectory:YES]; + NSURL *fileURL = [[tmpDirURL URLByAppendingPathComponent:@"SVWebTemp"] URLByAppendingPathExtension:@"html"]; + + [pageHTMLString writeToFile:[fileURL path] atomically:YES encoding:NSUTF8StringEncoding error:nil]; + self.URL = fileURL; + } + + return self; +} + - (void)loadURL:(NSURL *)pageURL { [self.webView loadRequest:[NSURLRequest requestWithURL:pageURL]]; } From 244278e03481e03a36c675987df35681295a3b1a Mon Sep 17 00:00:00 2001 From: FrankWu100 Date: Fri, 29 Nov 2013 05:26:17 +0800 Subject: [PATCH 3/6] Updated initWithHTMLString can set customURL MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - (id)initWithHTMLString:(NSString*)HTMLString; When loading web only from HTMLString and didn’t set customURL, the actionButton will be disable. - (id)initWithHTMLString:(NSString*)HTMLString customURL:(NSURL*)URL; When loading web from HTMLString and have set customURL, the actionButton will be enable, and use customURL to share URL. --- SVWebViewController/SVWebViewController.h | 1 + SVWebViewController/SVWebViewController.m | 35 +++++++++++++++++++++-- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/SVWebViewController/SVWebViewController.h b/SVWebViewController/SVWebViewController.h index 9310a0b..1946a38 100644 --- a/SVWebViewController/SVWebViewController.h +++ b/SVWebViewController/SVWebViewController.h @@ -13,5 +13,6 @@ - (id)initWithAddress:(NSString*)urlString; - (id)initWithURL:(NSURL*)URL; - (id)initWithHTMLString:(NSString*)HTMLString; +- (id)initWithHTMLString:(NSString*)HTMLString customURL:(NSURL*)URL; @end diff --git a/SVWebViewController/SVWebViewController.m b/SVWebViewController/SVWebViewController.m index ef48e8b..56c30f3 100644 --- a/SVWebViewController/SVWebViewController.m +++ b/SVWebViewController/SVWebViewController.m @@ -20,10 +20,12 @@ @interface SVWebViewController () @property (nonatomic, strong) UIWebView *webView; @property (nonatomic, strong) NSURL *URL; +@property (nonatomic, strong) NSURL *customURL; - (id)initWithAddress:(NSString*)urlString; - (id)initWithURL:(NSURL*)URL; - (id)initWithHTMLString:(NSString*)HTMLString; +- (id)initWithHTMLString:(NSString*)HTMLString customURL:(NSURL*)URL; - (void)loadURL:(NSURL*)URL; - (void)updateToolbarItems; @@ -73,6 +75,17 @@ - (id)initWithHTMLString:(NSString*)pageHTMLString { return self; } +- (id)initWithHTMLString:(NSString*)pageHTMLString customURL:(NSURL*)pageCustomURL { + + if(self = [super init]) { + self = [self initWithHTMLString:pageHTMLString]; + + self.customURL = pageCustomURL; + } + + return self; +} + - (void)loadURL:(NSURL *)pageURL { [self.webView loadRequest:[NSURLRequest requestWithURL:pageURL]]; } @@ -188,7 +201,16 @@ - (UIBarButtonItem *)actionBarButtonItem { - (void)updateToolbarItems { self.backBarButtonItem.enabled = self.self.webView.canGoBack; self.forwardBarButtonItem.enabled = self.self.webView.canGoForward; - self.actionBarButtonItem.enabled = !self.self.webView.isLoading; + + NSURL *tmpDirURL = [NSURL fileURLWithPath:NSTemporaryDirectory() isDirectory:YES]; + NSURL *fileURL = [[tmpDirURL URLByAppendingPathComponent:@"SVWebTemp"] URLByAppendingPathExtension:@"html"]; + + if ([self.self.webView.request.URL isEqual:fileURL] && self.customURL == NULL) { + self.actionBarButtonItem.enabled = FALSE; // + } + else { + self.actionBarButtonItem.enabled = !self.self.webView.isLoading; + } UIBarButtonItem *refreshStopBarButtonItem = self.self.webView.isLoading ? self.stopBarButtonItem : self.refreshBarButtonItem; @@ -277,8 +299,17 @@ - (void)stopClicked:(UIBarButtonItem *)sender { - (void)actionButtonClicked:(id)sender { NSArray *activities = @[[SVWebViewControllerActivitySafari new], [SVWebViewControllerActivityChrome new]]; + UIActivityViewController *activityController; - UIActivityViewController *activityController = [[UIActivityViewController alloc] initWithActivityItems:@[self.self.webView.request.URL] applicationActivities:activities]; + NSURL *tmpDirURL = [NSURL fileURLWithPath:NSTemporaryDirectory() isDirectory:YES]; + NSURL *fileURL = [[tmpDirURL URLByAppendingPathComponent:@"SVWebTemp"] URLByAppendingPathExtension:@"html"]; + + if ([self.self.webView.request.URL isEqual:fileURL]) { //&& self.customURL != NULL + activityController = [[UIActivityViewController alloc] initWithActivityItems:@[self.customURL] applicationActivities:activities]; + } + else { + activityController = [[UIActivityViewController alloc] initWithActivityItems:@[self.self.webView.request.URL] applicationActivities:activities]; + } [self presentViewController:activityController animated:YES completion:nil]; } From 3221f0696081da11dbcf5f380686669259634145 Mon Sep 17 00:00:00 2001 From: FrankWu100 Date: Fri, 29 Nov 2013 06:04:32 +0800 Subject: [PATCH 4/6] Refactored SVWebController's get tempFilePath's function --- SVWebViewController/SVWebViewController.m | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/SVWebViewController/SVWebViewController.m b/SVWebViewController/SVWebViewController.m index 56c30f3..6bac1e3 100644 --- a/SVWebViewController/SVWebViewController.m +++ b/SVWebViewController/SVWebViewController.m @@ -20,6 +20,7 @@ @interface SVWebViewController () @property (nonatomic, strong) UIWebView *webView; @property (nonatomic, strong) NSURL *URL; +@property (nonatomic, strong) NSURL *tempFilePath; @property (nonatomic, strong) NSURL *customURL; - (id)initWithAddress:(NSString*)urlString; @@ -66,10 +67,10 @@ - (id)initWithHTMLString:(NSString*)pageHTMLString { if(self = [super init]) { NSURL *tmpDirURL = [NSURL fileURLWithPath:NSTemporaryDirectory() isDirectory:YES]; - NSURL *fileURL = [[tmpDirURL URLByAppendingPathComponent:@"SVWebTemp"] URLByAppendingPathExtension:@"html"]; + self.tempFilePath = [[tmpDirURL URLByAppendingPathComponent:@"SVWebTemp"] URLByAppendingPathExtension:@"html"]; - [pageHTMLString writeToFile:[fileURL path] atomically:YES encoding:NSUTF8StringEncoding error:nil]; - self.URL = fileURL; + [pageHTMLString writeToFile:[self.tempFilePath path] atomically:YES encoding:NSUTF8StringEncoding error:nil]; + self.URL = self.tempFilePath; } return self; @@ -202,10 +203,7 @@ - (void)updateToolbarItems { self.backBarButtonItem.enabled = self.self.webView.canGoBack; self.forwardBarButtonItem.enabled = self.self.webView.canGoForward; - NSURL *tmpDirURL = [NSURL fileURLWithPath:NSTemporaryDirectory() isDirectory:YES]; - NSURL *fileURL = [[tmpDirURL URLByAppendingPathComponent:@"SVWebTemp"] URLByAppendingPathExtension:@"html"]; - - if ([self.self.webView.request.URL isEqual:fileURL] && self.customURL == NULL) { + if ([self.self.webView.request.URL isEqual:self.tempFilePath] && self.customURL == NULL) { self.actionBarButtonItem.enabled = FALSE; // } else { @@ -301,10 +299,7 @@ - (void)actionButtonClicked:(id)sender { NSArray *activities = @[[SVWebViewControllerActivitySafari new], [SVWebViewControllerActivityChrome new]]; UIActivityViewController *activityController; - NSURL *tmpDirURL = [NSURL fileURLWithPath:NSTemporaryDirectory() isDirectory:YES]; - NSURL *fileURL = [[tmpDirURL URLByAppendingPathComponent:@"SVWebTemp"] URLByAppendingPathExtension:@"html"]; - - if ([self.self.webView.request.URL isEqual:fileURL]) { //&& self.customURL != NULL + if ([self.self.webView.request.URL isEqual:self.tempFilePath]) { //&& self.customURL != NULL activityController = [[UIActivityViewController alloc] initWithActivityItems:@[self.customURL] applicationActivities:activities]; } else { From 800166bc35254b910bd0ffd1b85391c7eb954c92 Mon Sep 17 00:00:00 2001 From: FrankWu100 Date: Fri, 29 Nov 2013 17:15:32 +0800 Subject: [PATCH 5/6] Fix URL compare issue --- SVWebViewController/SVWebViewController.m | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/SVWebViewController/SVWebViewController.m b/SVWebViewController/SVWebViewController.m index 6bac1e3..d313416 100644 --- a/SVWebViewController/SVWebViewController.m +++ b/SVWebViewController/SVWebViewController.m @@ -20,7 +20,7 @@ @interface SVWebViewController () @property (nonatomic, strong) UIWebView *webView; @property (nonatomic, strong) NSURL *URL; -@property (nonatomic, strong) NSURL *tempFilePath; +@property (nonatomic, strong) NSString *tempFilePath; @property (nonatomic, strong) NSURL *customURL; - (id)initWithAddress:(NSString*)urlString; @@ -67,10 +67,11 @@ - (id)initWithHTMLString:(NSString*)pageHTMLString { if(self = [super init]) { NSURL *tmpDirURL = [NSURL fileURLWithPath:NSTemporaryDirectory() isDirectory:YES]; - self.tempFilePath = [[tmpDirURL URLByAppendingPathComponent:@"SVWebTemp"] URLByAppendingPathExtension:@"html"]; + NSURL *filePath = [[tmpDirURL URLByAppendingPathComponent:@"SVWebTemp"] URLByAppendingPathExtension:@"html"]; + self.tempFilePath = [filePath path]; - [pageHTMLString writeToFile:[self.tempFilePath path] atomically:YES encoding:NSUTF8StringEncoding error:nil]; - self.URL = self.tempFilePath; + [pageHTMLString writeToFile:self.tempFilePath atomically:YES encoding:NSUTF8StringEncoding error:nil]; + self.URL = [NSURL URLWithString:self.tempFilePath]; } return self; @@ -203,7 +204,7 @@ - (void)updateToolbarItems { self.backBarButtonItem.enabled = self.self.webView.canGoBack; self.forwardBarButtonItem.enabled = self.self.webView.canGoForward; - if ([self.self.webView.request.URL isEqual:self.tempFilePath] && self.customURL == NULL) { + if ([[self.self.webView.request.URL path] isEqualToString:self.tempFilePath] && self.customURL == NULL) { self.actionBarButtonItem.enabled = FALSE; // } else { @@ -299,7 +300,7 @@ - (void)actionButtonClicked:(id)sender { NSArray *activities = @[[SVWebViewControllerActivitySafari new], [SVWebViewControllerActivityChrome new]]; UIActivityViewController *activityController; - if ([self.self.webView.request.URL isEqual:self.tempFilePath]) { //&& self.customURL != NULL + if ([[self.self.webView.request.URL path] isEqualToString:self.tempFilePath]) { //&& self.customURL != NULL activityController = [[UIActivityViewController alloc] initWithActivityItems:@[self.customURL] applicationActivities:activities]; } else { From 7b16f27f5278b963835bb34a016220bcc5e575cf Mon Sep 17 00:00:00 2001 From: FrankWu100 Date: Fri, 29 Nov 2013 17:29:34 +0800 Subject: [PATCH 6/6] Fix URL not set bug --- SVWebViewController/SVWebViewController.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SVWebViewController/SVWebViewController.m b/SVWebViewController/SVWebViewController.m index d313416..7ab8406 100644 --- a/SVWebViewController/SVWebViewController.m +++ b/SVWebViewController/SVWebViewController.m @@ -69,9 +69,9 @@ - (id)initWithHTMLString:(NSString*)pageHTMLString { NSURL *tmpDirURL = [NSURL fileURLWithPath:NSTemporaryDirectory() isDirectory:YES]; NSURL *filePath = [[tmpDirURL URLByAppendingPathComponent:@"SVWebTemp"] URLByAppendingPathExtension:@"html"]; self.tempFilePath = [filePath path]; - [pageHTMLString writeToFile:self.tempFilePath atomically:YES encoding:NSUTF8StringEncoding error:nil]; - self.URL = [NSURL URLWithString:self.tempFilePath]; + + self.URL = filePath; } return self;