如何创建链接到Safari的按钮? [英] How to create a button that links to Safari?

查看:115
本文介绍了如何创建链接到Safari的按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

出于法律原因,我有义务在我的应用程序中显示服务条款,在外部服务器上显示PDF。我认为最简单的方法是创建一个UIBarButton项,然后创建一个在Safari中启动链接的IBAction。

For legal reasons, I'm obligated to show Terms of Service in my application, a PDF on an external server. What I believe would be easiest to do would be to create a UIBarButton item and then create an IBAction that launches the link in Safari.

所以我创建一个按钮:

IBOutlet UIBarButtonItem *legal;

然后我把它变成一个非原子属性并在我的实现文件中合成它,对吗?我继续创建一个IBAction:

Then I make it into a nonatomic property and synthesize it in my implementation file, right? I go on to create an IBAction:

-(IBAction)legalButtonPressed:(id)sender;

我进入我的实施文件,这就是问题所在。在定义这些行动时,我感到困惑。由于我是iOS开发的新手,我可以使用一些指导。我不知道如何强制链接到动作中的safari。任何帮助将不胜感激!

I go into my implementation file, and here's where the issue comes. When it comes to defining those actions, I become confused. As I am new to iOS development, I could use some guidance. I don't know how to force the link into safari in the action. Any help would be greatly appreciated!

谢谢!

推荐答案

IBOutlet和IBActions用于Interface Builder连接。如果您在xib文件上有UIBarButtonItem,则可以通过右键单击文件所有者对象将其操作连接到控制器。与插座相同。

IBOutlet and IBActions are used for Interface Builder connections. If you have your UIBarButtonItem on a xib file, you can connect its action to the controller by right clicking in the files owner object. The same with the outlet.

一旦你在连接到xib文件中的按钮的控制器中执行操作,(我认为不需要在这里获得插座),你只需实现如下方法:

Once you have the action in the controller connected to the button in the xib file, (I see no need to get an outlet here), you just implement the method as follows:

-(IBAction)legalButtonPressed:(id)sender {
     [[UIApplication sharedApplication] openURL:[NSURL URLWithString: @"http://yourdomain.com/legal.pdf"]];
}

这将自动打开带有给定网址的safari

this will automatically open safari with the given url

这篇关于如何创建链接到Safari的按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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