Here is my code,
How to open the link only via chrome browser?
NSString* url = @"some url";
NSURL *inputURL = [NSURL URLWithString:url];
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];
}
I have even added the following in .plist,
<key>LSApplicationQueriesSchemes</key>
<array>
<string>googlechrome</string>
</array>
But still it is not working.
First Of All Make Sure You have installed Google Chrome browser application in your test iPhone device. If you are testing this code into simulator, then it will not work, because Google Chrome browser app can not be installed in Xcode simulator.On iPhone Device You can check the installation of chrome application in following way
//Check if Google Chrome is Instaled
if ([[UIApplication sharedApplication] canOpenURL:chromeURL]) {
//open URL in Google chrome browser app
[[UIApplication sharedApplication] openURL:chromeURL];
}
else
{
//Remove Google Chrome Scheme at start of application and open link in safari append http or https at start
[[UIApplication sharedApplication] openURL:safariURL];
}
Your code is working fine
Result One
Applicarion in running form