Skip to content
This repository has been archived by the owner on Apr 27, 2021. It is now read-only.

Follow Apple advice for deprecated CFURL method. #5

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
24 changes: 11 additions & 13 deletions OpenInChromeController.m
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,7 @@
static NSString * const kGoogleChromeCallbackScheme = @"googlechrome-x-callback:";

static NSString *encodeByAddingPercentEscapes(NSString *input) {
NSString *encodedValue = (NSString *)CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(
kCFAllocatorDefault,
(CFStringRef)input,
NULL,
(CFStringRef)@"!*'();:@&=+$,/?%#[]",
kCFStringEncodingUTF8));
return encodedValue;
return [input stringByAddingPercentEncodingWithAllowedCharacters: NSCharacterSet.URLQueryAllowedCharacterSet];
}

@implementation OpenInChromeController
Expand All @@ -61,10 +55,12 @@ + (OpenInChromeController *)sharedInstance {
}

- (BOOL)isChromeInstalled {
NSURL *simpleURL = [NSURL URLWithString:kGoogleChromeHTTPScheme];
NSURL *callbackURL = [NSURL URLWithString:kGoogleChromeCallbackScheme];
return [[UIApplication sharedApplication] canOpenURL:simpleURL] ||
[[UIApplication sharedApplication] canOpenURL:callbackURL];
NSURL *simpleURL = [NSURL URLWithString:kGoogleChromeHTTPScheme];
NSURL *secureURL = [NSURL URLWithString:kGoogleChromeHTTPSScheme];
NSURL *callbackURL = [NSURL URLWithString:kGoogleChromeCallbackScheme];
return ([[UIApplication sharedApplication] canOpenURL:simpleURL] ||
[[UIApplication sharedApplication] canOpenURL:secureURL] ||
[[UIApplication sharedApplication] canOpenURL:callbackURL]);
}

- (BOOL)openInChrome:(NSURL *)url {
Expand All @@ -74,7 +70,8 @@ - (BOOL)openInChrome:(NSURL *)url {
- (BOOL)openInChrome:(NSURL *)url
withCallbackURL:(NSURL *)callbackURL
createNewTab:(BOOL)createNewTab {
NSURL *chromeSimpleURL = [NSURL URLWithString:kGoogleChromeHTTPScheme];
NSURL *chromeSimpleURL = [NSURL URLWithString:kGoogleChromeHTTPScheme];
NSURL *chromeSecureURL = [NSURL URLWithString:kGoogleChromeHTTPSScheme];
NSURL *chromeCallbackURL = [NSURL URLWithString:kGoogleChromeCallbackScheme];
if ([[UIApplication sharedApplication] canOpenURL:chromeCallbackURL]) {
NSString *appName =
Expand Down Expand Up @@ -106,7 +103,8 @@ - (BOOL)openInChrome:(NSURL *)url
// Open the URL with Google Chrome.
return [[UIApplication sharedApplication] openURL:chromeURL];
}
} else if ([[UIApplication sharedApplication] canOpenURL:chromeSimpleURL]) {
} else if ([[UIApplication sharedApplication] canOpenURL:chromeSimpleURL] ||
[[UIApplication sharedApplication] canOpenURL:chromeSecureURL]) {
NSString *scheme = [url.scheme lowercaseString];

// Replace the URL Scheme with the Chrome equivalent.
Expand Down