From 3ff12da164dc057cbf3d64366e44cf6b41e95374 Mon Sep 17 00:00:00 2001 From: "Andrew W. Donoho" Date: Sun, 15 Nov 2015 22:34:49 -0600 Subject: [PATCH 1/2] Follow Apple advice for deprecated CFURL method. --- OpenInChromeController.m | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/OpenInChromeController.m b/OpenInChromeController.m index 5758802..1eed0ed 100644 --- a/OpenInChromeController.m +++ b/OpenInChromeController.m @@ -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 From 7dc2d8a6c3365bc9de09716b30dabcf1d07a56ec Mon Sep 17 00:00:00 2001 From: "Andrew W. Donoho" Date: Wed, 18 Nov 2015 15:40:04 -0600 Subject: [PATCH 2/2] Update to use iOSv7+ encoding routines. --- OpenInChromeController.m | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/OpenInChromeController.m b/OpenInChromeController.m index 5758802..45e2903 100644 --- a/OpenInChromeController.m +++ b/OpenInChromeController.m @@ -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 @@ -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 { @@ -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 = @@ -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.