【IOS9】Quick Take on iOS 9 URL Scheme Changes

Quick Take on iOS 9 URL Scheme Changes

[UPDATE #2: I have independent confirmation from several sources that these limitations are meant to only apply to “canOpenURL” and it is a bug that they are also effecting “openURL”. There are still implications, and many apps will need some updates, but that’s not so dramatic a change.]

[UPDATE: The more I think about this and get feedback from people on Twitter, the more I think these limitations on “openURL” have to be a bug. It would break too many things (like login workflows for Facebook/Dropbox). There are still significant side effects from the change to canOpenURL alone, but surmountable ones.]

During Session 703, “Privacy and Your App”, at WWDC 2015 (video), Apple discussed changes impacting URL schemes on iOS 9. URLs are used extensively by some of my apps, so this piqued my interest. This post is a quick summary of how I understand the changes and their impact. Some of this could turn out to be wrong or change before iOS 9’s final release, but I thought I’d get the discussion going.

What are URL schemes?

I will not attempt to define URL, but suffice to say URLs are the part and parcel of navigation on the Internet. You are likely quite familiar with web URLs like “http://apple.com”. The first part of a URL, the part before the colon, is the URL scheme. The scheme is used to identify the type of service required to understand the URL, and most operating systems have a mechanism for applications to register that they are capable of opening URLs with certain URL schemes. The common example being the web browsers registering to open “http” and “https” URL schemes so that web links will open in the browser.

iOS has a system for registering URLs schemes as well. Some URL schemes, like “http” and “mailto” are reserved by Apple to point to their own Safari and Mail apps, but apps installed from the App Store can register to handle other arbitrary URL schemes.

Custom URL schemes like these are used by many apps for a variety of purposes. A common use is to deep link to a particular piece of content within an app – seen as an “Open in app” link from a web page.

Because of the limited available channels for apps to communicate with each other on iOS, URLs have been employed to expose functionality between apps as well. The iOS automation community has built a tremendous amount of functionality on top of URL schemes to allow apps to provide services, forward data to other apps, or simply launch other apps. If you use Drafts, Launch Center Pro, Workflow or many, many other apps, you are using and benefiting from URL schemes on iOS.

What is Apple Changing?

The key bits regarding changes to URL schemes in iOS 9 is the Privacy and Your Apps session, starting at around the 9 minute mark under the heading “App Detection”.

There are two URL-related methods available to apps on iOS that are effected: canOpenURL and openURL. These are not new methods and the methods themselves are not changing. As you might expect from the names, “canOpenURL” returns a yes or no answer after checking if there is any apps installed on the device that know how to handle a given URL. “openURL” is used to actually launch the URL, which will typically leave the app and open the URL in another app.

Up until iOS 9, apps have been able to call these methods on any arbitrary URLs. Starting on iOS 9, apps will have to declare what URL schemes they would like to be able to check for and open in the configuration files of the app as it is submitted to Apple. This is essentially a whitelist that can only be changed or added to by submitting an update to Apple. It appears that certain common URLs handled by system apps, like “http”, “https”, do not need to be explicitly whitelisted.

I have tested these limits in Xcode 7 with the initial iOS 9 beta pre-release with the following results:

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.

If you call the “openURL” method on a URL that is not in your whitelist, it will fail silently. A “This app is not allowed to query for scheme xxx” syslog entry will appear.

It was not clear from the session if these limits apply to the “openURL” call, but in actual testing it appears that they do. It is possible (I hope) this is a bug.

Per the discussion in the session, these limits will be retroactively enforced on apps built and submitted to the store prior to iOS 9 by the system, which will build it’s own whitelist of up to 50 URL schemes allowed for an app based on the actual calls made by the app. The session does not explicitly state a limit to the number of URL schemes that can be in the app’s own whitelist, but I have to assume 50, or some other reasonable limit will be enforced – likely by a validator when submitting apps to Apple.

In practice, this means URLs are now something that can only be used to check for and open a small number of known outside apps. For example, the way Google uses x-callback-url based URL callbacks to create “Back” buttons to return to other apps from their iOS versions of Chrome and Maps could still continue to work between their own family of apps which they would likely whitelist, but would not be able to continue to be used by other arbitrary apps wishing to make that “Back” button appear in Chrome.

This will also practically kill any sort of launcher app, and prevent apps like Drafts and Workflow from accessing services in other apps, chaining URL callbacks and other complicated automation tasks.

Why is Apple Making this Change?

Apple is making this change for privacy reasons.

Although any app can register any arbitrary URL schemes and there is no guarantee that because the system returns “YES” from a canOpenURL call that a particular app is actually installed, registering unique URL schemes has become a de facto way to check if a certain app is installed on the system – and by scanning lists of “known” URL schemes with canOpenURL, certain apps (like Twitter’s) have been abusing this loophole to scan your system for installed apps and used this information for whatever nefarious reasons – likely involving advertising.

Apple has been adding more secure and reliable ways to do many (but not all) of the things possible with URLs (Extensions, App Links, etc.). Long term these are important changes because it is true that there are implications to the uncontrolled use of URLs that may be exploited.

Possible Alternatives

I agree with Apple’s concerns regarding the abuse of “canOpenURL”, but if the current implementation is their intended solution, I believe it is too severe and will cause too much breakage and bad user experience for many users.

My hope is (as mentioned above) that these changes were only meant to apply to the “canOpenURL” method, and that it is a bug that they have also limited the functionality of the “openURL” call. I have filed a radar reporting this as a bug, if you are a developer and agree with my assessment please consider duplicating it (rdar://21320635 | openradar).

Even if that is the case, loss of the ability to call “canOpenURL” on arbitrary URLs will limit the user experience on many automation applications of URLs because an app has no way of testing if the URL can be opened successfully and will have to rely on the system to report errors. It might also be possible to allow it to continue to function for apps in a throttled fashion that would only allow a certain number of “canOpenURL” calls in a certain time period – thus hindering it’s usefulness for scanning.

I have not fully thought out the ramifications of this change, and it was made public yesterday – but I wanted to get some thoughts out quickly to start a discussion and hope Apple is listening and willing to make good compromises that protect users and allow iOS to continue to be as powerful and flexible as possible.

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個(gè)濱河市,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌鸭轮,老刑警劉巖,帶你破解...
    沈念sama閱讀 206,378評(píng)論 6 481
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件轿钠,死亡現(xiàn)場離奇詭異己单,居然都是意外死亡塞淹,警方通過查閱死者的電腦和手機(jī)玲昧,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 88,356評(píng)論 2 382
  • 文/潘曉璐 我一進(jìn)店門栖茉,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人孵延,你說我怎么就攤上這事吕漂。” “怎么了尘应?”我有些...
    開封第一講書人閱讀 152,702評(píng)論 0 342
  • 文/不壞的土叔 我叫張陵痰娱,是天一觀的道長。 經(jīng)常有香客問我菩收,道長,這世上最難降的妖魔是什么鲸睛? 我笑而不...
    開封第一講書人閱讀 55,259評(píng)論 1 279
  • 正文 為了忘掉前任娜饵,我火速辦了婚禮,結(jié)果婚禮上官辈,老公的妹妹穿的比我還像新娘箱舞。我一直安慰自己,他們只是感情好拳亿,可當(dāng)我...
    茶點(diǎn)故事閱讀 64,263評(píng)論 5 371
  • 文/花漫 我一把揭開白布晴股。 她就那樣靜靜地躺著,像睡著了一般肺魁。 火紅的嫁衣襯著肌膚如雪电湘。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 49,036評(píng)論 1 285
  • 那天鹅经,我揣著相機(jī)與錄音寂呛,去河邊找鬼。 笑死瘾晃,一個(gè)胖子當(dāng)著我的面吹牛贷痪,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播蹦误,決...
    沈念sama閱讀 38,349評(píng)論 3 400
  • 文/蒼蘭香墨 我猛地睜開眼劫拢,長吁一口氣:“原來是場噩夢啊……” “哼肉津!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起舱沧,我...
    開封第一講書人閱讀 36,979評(píng)論 0 259
  • 序言:老撾萬榮一對(duì)情侶失蹤妹沙,失蹤者是張志新(化名)和其女友劉穎,沒想到半個(gè)月后狗唉,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體初烘,經(jīng)...
    沈念sama閱讀 43,469評(píng)論 1 300
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 35,938評(píng)論 2 323
  • 正文 我和宋清朗相戀三年分俯,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了肾筐。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 38,059評(píng)論 1 333
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡缸剪,死狀恐怖吗铐,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情杏节,我是刑警寧澤唬渗,帶...
    沈念sama閱讀 33,703評(píng)論 4 323
  • 正文 年R本政府宣布,位于F島的核電站奋渔,受9級(jí)特大地震影響镊逝,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜嫉鲸,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 39,257評(píng)論 3 307
  • 文/蒙蒙 一撑蒜、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧玄渗,春花似錦座菠、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,262評(píng)論 0 19
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至岁钓,卻和暖如春升略,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背屡限。 一陣腳步聲響...
    開封第一講書人閱讀 31,485評(píng)論 1 262
  • 我被黑心中介騙來泰國打工降宅, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留,地道東北人囚霸。 一個(gè)月前我還...
    沈念sama閱讀 45,501評(píng)論 2 354
  • 正文 我出身青樓腰根,卻偏偏與公主長得像,于是被迫代替她去往敵國和親拓型。 傳聞我的和親對(duì)象是個(gè)殘疾皇子额嘿,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 42,792評(píng)論 2 345

推薦閱讀更多精彩內(nèi)容