-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6990b6a
commit fe5244c
Showing
16 changed files
with
533 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Copyright (c) 2012 Designated Nerd Software. | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRNATY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES, OR OTHER LIABILITY, WHETHER IN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// | ||
// NSURL+BrowserChooser.h | ||
// BrowserChooser | ||
// | ||
// Created by Ellen Shapiro on 7/14/12. | ||
// Copyright (c) 2012 Designated Nerd Software. | ||
// | ||
|
||
|
||
|
||
#import <Foundation/Foundation.h> | ||
|
||
/** | ||
* Enum for supported browser types. | ||
*/ | ||
typedef enum { | ||
BrowserTypeMobileSafari = 0, | ||
BrowserTypeChromeForiOS | ||
} BrowserType; | ||
|
||
@interface NSURL (BrowserChooser) | ||
|
||
/** | ||
* Opens the NSURL in the indicated browser. | ||
* @param browserType - The BrowserType as defined in the above enum you wish to use. | ||
*/ | ||
-(void)openInBrowser:(BrowserType)browserType; | ||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// | ||
// NSURL+BrowserChooser.m | ||
// BrowserChooser | ||
// | ||
// Created by Ellen Shapiro on 7/14/12. | ||
// Copyright (c) 2012 Designated Nerd Software. | ||
// | ||
|
||
#import "NSURL+BrowserChooser.h" | ||
|
||
@implementation NSURL (BrowserChooser) | ||
|
||
-(void)openInBrowser:(BrowserType)browserType | ||
{ | ||
switch (browserType) { | ||
case BrowserTypeMobileSafari: | ||
//Open in default browser. This part's easy. | ||
[[UIApplication sharedApplication] openURL:self]; | ||
break; | ||
case BrowserTypeChromeForiOS: | ||
//Check to make sure chrome is installed first: | ||
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"googlechrome://"]]) { | ||
NSString *originalScheme = [self scheme]; | ||
|
||
NSString *chromeSchemeToUse = nil; | ||
if ([originalScheme isEqualToString:@"http"]) { | ||
chromeSchemeToUse = @"googlechrome"; | ||
} else if ([originalScheme isEqualToString:@"https"]) { | ||
chromeSchemeToUse = @"googlechromes"; | ||
} | ||
|
||
//Proceed if there is a valid URL scheme available (things like ftp etc. will fail): | ||
if (chromeSchemeToUse) { | ||
NSString *absoluteString = [self absoluteString]; | ||
NSRange rangeForScheme = [absoluteString rangeOfString:@":"]; | ||
NSString *urlNoScheme = [absoluteString substringFromIndex:rangeForScheme.location]; | ||
NSString *chromeURLString = [chromeSchemeToUse stringByAppendingString:urlNoScheme]; | ||
NSURL *chromeURL = [NSURL URLWithString:chromeURLString]; | ||
|
||
[[UIApplication sharedApplication] openURL:chromeURL]; | ||
} else { | ||
//Inform the user the scheme could not be opened. | ||
NSString *title = NSLocalizedString(@"Sorry!", @"Sorry"); | ||
NSString *messagePrefix = NSLocalizedString(@"Google Chrome for iOS cannot open URLs that begin with", @"Chrome can't open prefix"); | ||
NSString *message = [NSString stringWithFormat:@"%@ %@.", messagePrefix, originalScheme]; | ||
NSString *ok = NSLocalizedString(@"OK", @"OK"); | ||
|
||
UIAlertView *noSchemeForYou = [[UIAlertView alloc] initWithTitle:title message:message delegate:nil cancelButtonTitle:ok otherButtonTitles:nil]; | ||
[noSchemeForYou show]; | ||
} | ||
} else { | ||
//Inform the user they need to install chrome. | ||
NSString *title = NSLocalizedString(@"Oops!", @"Oops"); | ||
NSString *message = NSLocalizedString(@"Chrome is not installed on your device. Please install Chrome on your device if you wish to open links with Chrome.", @"Chrome not installed, please install."); | ||
NSString *ok = NSLocalizedString(@"OK", @"OK"); | ||
UIAlertView *noChromeForYou = [[UIAlertView alloc] initWithTitle:title message:message delegate:nil cancelButtonTitle:ok otherButtonTitles:nil]; | ||
[noChromeForYou show]; | ||
} | ||
break; | ||
default: | ||
NSLog(@"Unknown browser type. Please check your code and try again."); | ||
break; | ||
} | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.