Date
Nov. 21st, 2024
 
2024年 10月 21日

Post: iOS 9 : URLScheme

iOS 9 : URLScheme

Published 12:09 Sep 18, 2015.

Created by @ezra. Categorized in #Programming, and tagged as #iOS.

Source format: Markdown

Table of Content

相信很多小伙伴即将开始着手 iOS 9 的适配工作了,下面我们就来了解一下 iOS 9 的一项新特性: URLScheme

URLScheme 白名单与 canOpenURL: 方法

在 iOS 9 中,苹果针对 URLScheme 又引入了新的白名单概念,在 WWDC 2015 Session 703: Privacy and Your App 中提到:

If you call the "canOpenURL" method on a URL that is not in your whitelist, it will return "NO", even if there is an app installed that has registered to handle this scheme. A "This app is not allowed to query for scheme xxx" syslog entry will appear.

如果在 iOS 9 中调用 canOpenURL: 方法,则所涉及的 URLScheme 必须在 Info.plist 中列入白名单才能使用,否则该方法会返回 NO

加入白名单的方法为:

<key>LSApplicationQueriesSchemes</key>
<array>
    <string>urlscheme1</string>
    <string>urlscheme2</string>
    <string>urlscheme3</string>
    <string>urlscheme4</string>
</array>

WWDC 2015 Session 703: Privacy and Your App 还有这样一段话:

So for apps that are linked before iOS 9 and are running on iOS 9, they will be given 50 distinct URL schemes.

也就是说,白名单也是有数量上限的,目前这个限制为50个。

此外在iOS 9 中另外一个方法 openURL: 也增加了一个 UIAlertView 形式的确认动作。

Pinned Message
HOTODOGO
The Founder and CEO of Infeca Technology.
Developer, Designer, Blogger.
Big fan of Apple, Love of colour.
Feel free to contact me.
反曲点科技创始人和首席执行官。
开发、设计与写作皆为所长。
热爱苹果、钟情色彩。
随时恭候 垂询