如何在iOS目标C中打开链接时启动Chrome浏览器

赤原

这是我的代码,

如何仅通过Chrome浏览器打开链接?

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];
}

我什至在.plist中添加了以下内容,

<key>LSApplicationQueriesSchemes</key>
    <array>
        <string>googlechrome</string>
    </array>

但是仍然无法正常工作。

哈菲兹·沙扎德·阿里

首先确定您已在测试的iPhone设备中安装了Google Chrome浏览器应用程序。如果您正在将此代码测试到模拟器中,则它将无法工作,因为无法在Xcode模拟器中安装Google Chrome浏览器应用。在iPhone设备上,您可以通过以下方式检查chrome应用程序的安装

//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];

    }

您的代码运行正常

代码尖峰

结果一

屏幕演示

运行形式的申请

最后结果

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何在浏览器中打开链接?

单击外部链接时如何在 WebView 应用程序中打开 Web 浏览器?

过滤表格时如何在 IE(非默认浏览器)中打开 Excel 超链接

C# .Net 6 - 如何在默认浏览器中打开链接?

如何使Google Chrome浏览器的“应用程序模式”在外部浏览器中打开外部链接?

在 Google 新闻网站中打开链接时的移动 Chrome 浏览器行为

当我单击Google Chrome浏览器中的链接时,Thunderbird帐户向导将打开

如何在golang中启动Web服务器在浏览器中打开页面?

如何在 .Net 5 Web API 项目启动时不打开 Web 浏览器

打开电子邮件中的链接时,如何更改Lotus Notes中的默认浏览器?

如何在Xamarin.Forms中修改WebView以在设备上的浏览器中打开链接?

单击时如何使Byobu终端在浏览器中打开超链接?

如何在默认浏览器中打开Evince超链接?

如何在默认浏览器中打开新链接而不是使用 Javascript 的 webview?

QWebEngineView-如何在系统浏览器中打开链接

如何在谷歌浏览器中打开本地文件系统链接?

如何在我的网络浏览器中打开这个 ppt 链接?

如何使用Electron在默认浏览器中打开链接

如何从CefSharp 3在本机浏览器中打开链接

如何在启动时阻止Google Chrome浏览器请求导入Firefox设置?

启动Chrome浏览器时如何安装插件?

启动For循环时如何修复Chrome /浏览器崩溃?

如何在Google Chrome浏览器中启动JavaScript调试器?

在AppleScript中打开多个Google Chrome浏览器窗口时,如何查找特定标签

在浏览器中打开Electron的链接

在特定的浏览器中打开链接

浏览器中的phonegap打开链接

如何在Android中以全屏或信息亭的形式打开Chrome浏览器

如何在Chrome浏览器中打开左侧的新标签?