Implementing Custom URL Schemes

1、Implementing Custom URL Schemes
If your app can receive specially formatted URLs, you should register the corresponding URL schemes with the
system. A custom URL scheme is a mechanism through which third-party apps can communicate with each
other. Apps often use custom URL schemes to vend services to other apps. For example, the Maps app supports

URLs for displaying specific map locations.

实现自定义的URL Schemes

如果你想让你的应用程序能够接收特定的、格式化的URLs,需要向系统中注册相应的URL schemes。自定义URL Scheme是一种机制,通过它,第三方应用能够相互通信。应用程序通常使用自定义的URL schemes为其它应用提供服务,例如,地图的应用提供显示指定位置的URLs。


2、Registering Custom URL Schemes
To register a URL type for your app, include the CFBundleURLTypes key in your app’s Info.plist file. The
CFBundleURLTypes key contains an array of dictionaries, each of which defines a URL scheme the app
supports. describes the keys and values to include in each dictionary.

注册自定义URL Schemes

注册URL type,需要向Info.plist文件中添加CFBundleURLTypes字段,CFBundleURLTypes对应一个数组,数组中的对象是字典,每个字典中定义了一个应用支持的URL scheme,下面列出了字典中的keys和values。

CFBundleURLName 

A string containing the abstract name of the URL scheme. To ensure uniqueness, it is recommended that you specify a reverse-DNS style of identifier, for example, com.acme.myscheme. The string you specify is also used as a key in your app’s InfoPlist.strings file. The value of the key is the human-readable scheme name.

CFBundleURLSchemes

An array of strings containing the URL scheme names—for example, http, mailto, tel, and sms.

CFBundleURLName 包含URL scheme的抽象名称,为了保证独一无二,推荐使用域名的倒序样式来定义,例如,com.acme.myscheme。同时可以在InfoPlist.strings文件中定义一个key为CFBundleURLName的键值对,其值是一个可读的scheme名。

CFBundleURLSchemes 是一个包含URL scheme名称的数组,例如,http,mailto,tel和sms。


3、Handling URL Requests
An app that has its own custom URL scheme must be able to handle URLs passed to it. All URLs are passed to
your app delegate, either at launch time or while your app is running or in the background. To handle incoming
URLs, your delegate should implement the following methods:
● Use the application:willFinishLaunchingWithOptions: and application:didFinishLaunchingWithOptions: methods to retrieve information about the URL and decide whether you want to open it. If either method returns NO, your app’s URL handling code is not called.
● In iOS 4.2 and later, use the application:openURL:sourceApplication:annotation: method to open the file.
If your app is not running when a URL request arrives, it is launched and moved to the foreground so that it
can open the URL. The implementation of your application:willFinishLaunchingWithOptions: or
application:didFinishLaunchingWithOptions: method should retrieve the URL from its options
dictionary and determine whether the app can open it. If it can, return YES and let your
application:openURL:sourceApplication:annotation: (or application:handleOpenURL:) method handle the actual opening of the URL. (If you implement both methods, both must return YES before
the URL can be opened.) Figure 6-1 shows the modified launch sequence for an app that is asked to open a
URL.

处理URL请求

一个应用程序拥有自定义的URL scheme,就必须能够处理相应的URL请求,所有的URLs请求都会发送到应用程序的delegate,不论是在启动阶段还是应用在运行或者在后台,为了处理URL请求,delegate需要实现下面的方法:

●用application:willFinishLaunchingWithOptions: 或者 application:didFinishLaunchingWithOptions: 这两个方法获取到URL的信息,并且判断是否要打开此URL,只要两个方法中有一个返回NO,处理URL请求的代码就不会执行。

●在iOS4.2或者以后的版本中,使用application:openURL:sourceApplication:annotation:此方法来打开URL。

当一个URL请求时,应用程序未启动,启动并呈现这个可以打开的URL,这两个方法application:willFinishLaunchingWithOptions: 或者 application:didFinishLaunchingWithOptions: 接受到URL信息判断应用程序是否可以打开它,返回YES 就调用application:openURL:sourceApplication:annotation方法来打开URL,URL启动应用的流程如下:



如果应用已经在运行或者在后台时的执行流程如下:


以上是对apple官方文档中Custom URL Scheme的部分翻译,有翻译不对的或者理解错误的地方,还请各位大侠指正。我的微信公众账号是:DeveloperCave,有兴趣的同学可以加下,共同学习ios开发。另外,根据这个翻译写了一个小demo,可以点击此处下载。







  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
使用Ansible实施DevOps 2有助于实现更高效的软件开发和运维流程。Ansible是一款开源的自动化工具,它提供了一种简单而强大的方式来自动化配置管理、应用部署和任务协调。 首先,使用Ansible可以实现基础设施即代码(Infrastructure as Code)。通过编写Ansible Playbooks,可以将整个基础设施的配置进行版本控制,并将其文档化。这样,团队成员可以更容易地理解和复制该基础设施。使用Ansible还可以轻松地在不同环境(例如开发、测试和生产)之间进行配置代码的复用,减少了配置的冗余和手动操作的错误。 其次,Ansible可以实现自动化部署。使用Ansible Playbooks,可以减少手动操作,从而降低了人为错误的风险。通过定义各个部署步骤和依赖关系,可以确保每个部署流程的一致性和可靠性。此外,Ansible还支持滚动更新,在保持应用的可用性的同时逐步更新。 此外,Ansible具有良好的扩展性和灵活性。能够与各种不同的工具和平台集成,例如CI/CD工具、云平台和容器管理器(如Docker和Kubernetes)。这使得在DevOps中使用Ansible更加方便,可以根据需要定制个性化的自动化流程。 最后,Ansible还提供了丰富的日志和报告功能,可以帮助团队追踪和分析各个任务的执行情况,以及及时发现和解决问题。这些日志和报告可以与监控和告警系统集成,以最大限度地减少对人工干预的需求,提高故障排查和修复的效率。 总而言之,使用Ansible实施DevOps 2可以帮助团队提高软件开发和运维效率,减少人为错误,并实现更好的可维护性和可扩展性。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值