Skip to content

Commit

Permalink
Merge pull request TransitApp#104 from mshibanami/master
Browse files Browse the repository at this point in the history
Localization files are not included When install this library with CocoaPods,
  • Loading branch information
gcamp committed Jul 15, 2014
2 parents 405dc88 + ad4647e commit 8da1871
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 16 deletions.
2 changes: 1 addition & 1 deletion SVWebViewController.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ Pod::Spec.new do |s|
s.source = { :git => 'https://github.com/samvermette/SVWebViewController.git', :tag => s.version.to_s }
s.platform = :ios, '6.0'
s.source_files = 'SVWebViewController/**/*.{h,m}'
s.resources = 'SVWebViewController/**/*.{bundle,png}'
s.resources = 'SVWebViewController/**/*.{bundle,png,lproj}'
s.requires_arc = true
end
17 changes: 12 additions & 5 deletions SVWebViewController/SVWebViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,7 @@ - (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;


UIBarButtonItem *refreshStopBarButtonItem = self.self.webView.isLoading ? self.stopBarButtonItem : self.refreshBarButtonItem;

UIBarButtonItem *fixedSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
Expand Down Expand Up @@ -266,9 +265,17 @@ - (void)stopClicked:(UIBarButtonItem *)sender {

- (void)actionButtonClicked:(id)sender {
NSArray *activities = @[[SVWebViewControllerActivitySafari new], [SVWebViewControllerActivityChrome new]];
NSURL *url = self.webView.request.URL ? self.webView.request.URL : self.URL;
UIActivityViewController *activityController = [[UIActivityViewController alloc] initWithActivityItems:@[url] applicationActivities:activities];
[self presentViewController:activityController animated:YES completion:nil];
NSURL *url = self.self.webView.request.URL;
if (!url || [[url absoluteString] isEqualToString:@""]) {
url = self.URL;
}
if ([[url absoluteString] hasPrefix:@"file:///"]) {
UIDocumentInteractionController *dc = [UIDocumentInteractionController interactionControllerWithURL:url];
[dc presentOptionsMenuFromRect:self.view.bounds inView:self.view animated:YES];
} else {
UIActivityViewController *activityController = [[UIActivityViewController alloc] initWithActivityItems:@[url] applicationActivities:activities];
[self presentViewController:activityController animated:YES completion:nil];
}
}

- (void)doneButtonClicked:(id)sender {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,44 @@

@implementation SVWebViewControllerActivityChrome

- (NSString *)schemePrefix {
return @"googlechrome://";
}

- (NSString *)activityTitle {
return NSLocalizedStringFromTable(@"Open in Chrome", @"SVWebViewController", nil);
}

- (BOOL)canPerformWithActivityItems:(NSArray *)activityItems {
for (id activityItem in activityItems) {
if ([activityItem isKindOfClass:[NSURL class]] && [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:self.schemePrefix]]) {
if ([activityItem isKindOfClass:[NSURL class]] && [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"googlechrome://"]]) {
return YES;
}
}
return NO;
}

- (void)performActivity {
NSString *openingURL = [self.URLToOpen.absoluteString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL *activityURL = [NSURL URLWithString:[NSString stringWithFormat:@"%@%@", self.schemePrefix, openingURL]];
[[UIApplication sharedApplication] openURL:activityURL];

[self activityDidFinish:YES];
NSURL *inputURL = self.URLToOpen;
NSString *scheme = inputURL.scheme;

// Replace the URL Scheme with the Chrome equivalent.
NSString *chromeScheme = nil;
if ([scheme isEqualToString:@"http"]) {
chromeScheme = @"googlechrome";
} else if ([scheme isEqualToString:@"https"]) {
chromeScheme = @"googlechromes";
}

// Proceed only if a valid Google Chrome URI Scheme is available.
if (chromeScheme) {
NSString *absoluteString = [inputURL absoluteString];
NSRange rangeForScheme = [absoluteString rangeOfString:@":"];
NSString *urlNoScheme =
[absoluteString substringFromIndex:rangeForScheme.location];
NSString *chromeURLString =
[chromeScheme stringByAppendingString:urlNoScheme];
NSURL *chromeURL = [NSURL URLWithString:chromeURLString];

// Open the URL with Chrome.
[[UIApplication sharedApplication] openURL:chromeURL];
}
}

@end

0 comments on commit 8da1871

Please sign in to comment.