目录
1、在xcode中设置如何被url scheme唤起并获取启动参数
要说明它的工作原理还要细谈微软关于注册应用程序协议的说明 Registering an Application to a URL Protocol
此文中对于 Windows、Linux 和 OS X 操作系统如何注册协议都有说明。比如说 Windows,其实只需写入注册表,即可实现协议与执行程序的关联。
方法一:
Windows实现:
1、web端
.html测试文件
<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<div>
<a href="MyTestApp://">
open
</a>
</div>
</body>
</html>
2、客户端写入注册表
新建.reg文件,双击运行即可
Windows Registry Editor Version5.00 //注册表版本工具信息(也可自行修改)
[HKEY_CLASSES_ROOT\MyTestApp] //在HKEY_CLASSES_ROOT下面添加项,其中MyTestApp的名称就对应着自定义URL Protocol的名称,在web中调用的时候需要这个名称;
@="MyTestApp" //自定义名称,可以任意,后续并没有用到;
"URL Protocol"="D:\\MySoftware\\PaintAid\\PaintAid.exe" //指定应用程序的路径(.exe)
[HKEY_CLASSES_ROOT\MyTestApp\DefaultIcon]
@="D:\\MySoftware\\PaintAid\\PaintAid.exe,1"
[HKEY_CLASSES_ROOT\MyTestApp\shell]
[HKEY_CLASSES_ROOT\MyTestApp\shell\open]
[HKEY_CLASSES_ROOT\MyTestApp\shell\open\command]
@="\"D:\\MySoftware\\PaintAid\\PaintAid.exe\" \"%1\""
此注册表就是当浏览器调用 MytestApp://… 时,自动调用 Text.exe,并把 MytestApp://… 地址作为第一个参数传递给 Text.exe,再由Text.exe 解析参数。
写入成功: