繁体   English   中英

在网站上嵌入iOS URL方案

[英]Embedding a iOS URL Scheme on a website

我目前正在开发一个iOS应用,其中用户按下应用内的一个按钮,则此按钮应为到外部网站的简单链接,然后该网站应使用URL方案在该应用上启动GoodReader应用(如果已安装) iPad兼容。

但是,该应用程序链接到的页面源代码到底是什么? 我发现好书的URL方案是

URL = @ “ghttp://www.example.com/myfile.pdf”

但是其余代码看起来如何?

谢谢!

如果您使用的是钛,则可以尝试以下方法:

单击按钮后,调用

Ti.Platform.openURL("ghttp://www.example.com/myfile.pdf");

如果网址方案正确且已安装google reader应用程序,它将打开该应用程序。

这是您在IBAction中需要的,以捕获按下按钮的操作:

NSURL *url = [NSURL URLWithString:@"ghttp://www.example.com/myfile.pdf"];

if (![[UIApplication sharedApplication] openURL:url])
{
    NSLog(@"Cannot open url: %@",[url description]);
}
  • 在您的ViewController.m文件中,添加此功能

    -(IBAction)openGoogleReader:(id)sender {NSURL * url = [NSURL URLWithString:@“ ghttp://www.example.com/myfile.pdf”];

     if (![[UIApplication sharedApplication] openURL:url]) { NSLog(@"Cannot open url: %@",[url description]); } 

    }

然后,在此ViewController的.xib文件(或情节提要)中,按住Ctrl键并按鼠标左键,然后拖动到ViewController对象(黄色),然后在“已发送事件”中选择openGoogleReader :。 您可以在下面看到一个示例

在此处输入图片说明

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM