xcode 按下按钮从应用程序打开网页

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1240372/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 18:43:20  来源:igfitidea点击:

press button to open web page from app

iphonexcodewebpage

提问by

I have an app that I want to interact with a web page. Basically I want to press a button and the web page will open in a new view...

我有一个要与网页交互的应用程序。基本上我想按下一个按钮,网页将在新视图中打开......

Sorry I wasn't clear, I am developing on a Mac for an iPhone. Currently I have a "locate me" app that displays your Latitude and Longitude. I want to use those variables to populate 2 of the blanks on a PHP web page/form I have developed.

抱歉,我不清楚,我正在为 iPhone 开发 Mac。目前我有一个“定位我”的应用程序,可以显示你的纬度和经度。我想使用这些变量来填充我开发的 PHP 网页/表单上的 2 个空格。

I have added a label and button to my current app, when the button is pressed the URL with the Lat and Long (as passed vars) are displayed in the label. I want those vars to appear on my web page. Hope this is clearer...

我在我当前的应用程序中添加了一个标签和按钮,当按下按钮时,带有 Lat 和 Long(作为传递的变量)的 URL 显示在标签中。我希望这些变量出现在我的网页上。希望这更清楚...



Solved:I just added these lines of code I found here:

已解决:我刚刚添加了我在这里找到的这些代码行:

NSURL *url = [ [ NSURL alloc ] initWithString: @"http://www.cnn.com" ];

[[UIApplication sharedApplication] openURL:url];

回答by Norman

Since you tagged it as xcode, I assume you are using a Mac? Or is this an iPhone question? Either way, I'd suggest looking in the /Developer/Examples/WebKit folder on your development box. It contains a number of samples for displaying web pages. You'd then link the button to opening the web page by creating a new web document.

既然你把它标记为 xcode,我假设你使用的是 Mac?或者这是 iPhone 的问题?无论哪种方式,我都建议您查看开发盒上的 /Developer/Examples/WebKit 文件夹。它包含许多用于显示网页的示例。然后,您可以通过创建新的 Web 文档将按钮链接到打开网页。