如何从iOS应用程序启动safari和打开URL [英] How to launch safari and open URL from iOS app

查看:548
本文介绍了如何从iOS应用程序启动safari和打开URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在设置页面上,我想要包含三个链接

On the settings page, I want to include three links to


  • 我的应用支持网站

  • YouTube应用教程

  • 我的主要网站(即:链接到'由Dale Dietrich创建'标签。)

我搜索了这个网站以及网站和我的文档,但我发现没有什么是显而易见的。

I've searched this site and the web and my documentation and I've found nothing that is obvious.

注意:我不想在我的应用程序中打开网页,我只想将链接发送到Safari并在那里打开该链接。我已经看到许多应用程序在其设置页面中做同样的事情,所以它必须是可能的。

NOTE: I don't want to open web pages within my app, I just want to send the link to Safari and that link be open there. I've seen numbers of apps doing the same thing in their Settings page so it must be possible.

推荐答案

继承人我做了什么:


  1. 我在标题.h文件中创建了一个IBAction,如下所示:

  1. I created an IBAction in the header .h files as follows:

- (IBAction)openDaleDietrichDotCom:(id)sender;


  • 我在设置页面上添加了一个UIButton,其中包含我要链接到的文本。

  • I added a UIButton on the Settings page containing the text that I want to link to.

    我正确地将按钮连接到文件所有者的IBAction。

    I connected the button to IBAction in File Owner appropriately.

    然后实施以下:

    对象C

    - (IBAction)openDaleDietrichDotCom:(id)sender {
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.daledietrich.com"]];
    }
    

    Swift

    (viewController中的IBAction,而不是头文件)

    (IBAction in viewController, rather than header file)

    if let link = URL(string: "https://yoursite.com") {
      UIApplication.shared.open(link) 
    }
    

    这篇关于如何从iOS应用程序启动safari和打开URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆